如何在 Flex 4 TextInput 组件上设置圆角半径

发布于 2024-11-13 08:30:04 字数 168 浏览 2 评论 0原文

如何获取 Flex 4 中 TextInput 组件的角半径。

<s:TextInput prompt="username" width="150" maxChars="100" id="txt_username"
    color="#000000"/>

How do I get corner radius on my TextInput component in Flex 4.

<s:TextInput prompt="username" width="150" maxChars="100" id="txt_username"
    color="#000000"/>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

我不吻晚风 2024-11-20 08:30:04

创建自定义皮肤(可能通过复制 Spark TextInputSkin)并添加带有圆角的边框图形,如下所示:

<!-- border -->
<s:Rect id="border" left="0" right="0" top="0" bottom="0" 
        radiusX="10" radiusY="10">

    <s:stroke>
        <s:SolidColorStroke id="borderStroke" weight="1" />
    </s:stroke>
</s:Rect>

如果您想要更特殊的圆角,您还可以使用这些属性:

topLeftRadiusX="4" topLeftRadiusY="8" 
bottomLeftRadiusX="2" bottomRightRadiusY="10"

默认的 TextInputSkin 不允许圆角,因此有没有可以在 TextInput 上设置的样式来执行此操作。所以,不,除了创建自定义皮肤类之外没有其他方法。

Create a custom skin (possibly by copying spark TextInputSkin) and add a border graphic with rounded corners, like this:

<!-- border -->
<s:Rect id="border" left="0" right="0" top="0" bottom="0" 
        radiusX="10" radiusY="10">

    <s:stroke>
        <s:SolidColorStroke id="borderStroke" weight="1" />
    </s:stroke>
</s:Rect>

If you want more special rounded corners you can also use these attributes:

topLeftRadiusX="4" topLeftRadiusY="8" 
bottomLeftRadiusX="2" bottomRightRadiusY="10"

The default TextInputSkin does not allow for rounded corners, so there is no style that you could set on your TextInput to do it. So, no, there's no other way than creating a custom skin class.

一身仙ぐ女味 2024-11-20 08:30:04

您可以更进一步并使其充满活力。基于spark TextInputSkin 创建自定义TextInputSkin,并在updateDisplayList 方法中的super.updateDisplayList() 调用上方添加此代码。

在 YourTextInputSkin.mxml 中,

// in updateDisplayList()
if (getStyle("cornerRadius")!==undefined) {
    border.radiusX = border.radiusY = getStyle("cornerRadius");
    background.radiusX = background.radiusY = getStyle("cornerRadius");
}

就是这样。你完成了!

现在要使用它添加一个 CSS 类选择器来添加一个cornerRadius样式,如下所示:

/* set the Textinput.styleName to this style */

s|TextInput.roundedInput
{
    contentBackgroundAlpha: .4;
    contentBackgroundColor: #000000;
    cornerRadius:           10;
    skinClass:              ClassReference("view.skins.TextInputRoundedSkin");  
}

并将您的实例设置为该类,

<s:TextInput styleName="roundedInput"/>

不幸的是,您无法在MXML中的TextInput组件实例上设置cornerRadius样式。 Flex 是否应该像 HTML 标签那样支持这种类型的样式标签?皮肤中声明的样式是否应该代理到使用它们的组件?目前,如果您在 Skin 中声明了样式并尝试在组件实例上使用它,即使在 CSS 中声明该样式和任何其他样式都是有效的,Flex 编译器也会抛出错误。如果 UIComponents 有一个可以让您设置样式的样式代理对象怎么样?无论如何,我离题了。

如果除了前面的方法之外,您还想在 TextInput 实例上使用该样式,您可以通过扩展 TextInput 并向其中添加cornerRadius 样式元数据来实现。您还可以在使用时设置 SkinClass(内联或在库中的 defaults.css 文件中)。

像这样的东西:

<?xml version="1.0" encoding="utf-8"?>
<s:TextInput xmlns:fx="http://ns.adobe.com/mxml/2009" 
             xmlns:s="library://ns.adobe.com/flex/spark" 
             xmlns:mx="library://ns.adobe.com/flex/mx"
             skinClass="TextInputRoundedSkin" >
    <fx:Metadata>
        [Style(name="cornerRadius", inherit="no", type="uint")]
    </fx:Metadata>
</s:TextInput>

要使用,

<local:MyExtendedTextInput cornderRadius="8" />

将来您将不必声明 CSS。

You could take it a step further and make it dynamic. Create a custom TextInputSkin based on spark TextInputSkin and in the updateDisplayList method add this code above the super.updateDisplayList() call.

In YourTextInputSkin.mxml,

// in updateDisplayList()
if (getStyle("cornerRadius")!==undefined) {
    border.radiusX = border.radiusY = getStyle("cornerRadius");
    background.radiusX = background.radiusY = getStyle("cornerRadius");
}

That's it. You're done!

Now to use it add a CSS class selector to add a cornerRadius style like so:

/* set the Textinput.styleName to this style */

s|TextInput.roundedInput
{
    contentBackgroundAlpha: .4;
    contentBackgroundColor: #000000;
    cornerRadius:           10;
    skinClass:              ClassReference("view.skins.TextInputRoundedSkin");  
}

And set your instance to the class,

<s:TextInput styleName="roundedInput"/>

Unfortunately, you can't set the cornerRadius style on TextInput component instance in MXML. Should Flex support a styles tag for this type of thing like HTML tags do? Should styles declared in the Skin be proxied to the component using them? Currently the Flex compiler would throw an error if you declared a style in the Skin and tried to use it on the component instance even though it's valid to declare that style and any other style in the CSS. What about if UIComponents had a style proxy object that let you set styles? Anyway, I digress.

If you want to make that style available on the TextInput instance in addition to the previous methods you can do that by extending TextInput and adding the cornerRadius style metadata to it. You can also set the skinClass (inline or in a defaults.css file in the library) while you're at it.

Something like this:

<?xml version="1.0" encoding="utf-8"?>
<s:TextInput xmlns:fx="http://ns.adobe.com/mxml/2009" 
             xmlns:s="library://ns.adobe.com/flex/spark" 
             xmlns:mx="library://ns.adobe.com/flex/mx"
             skinClass="TextInputRoundedSkin" >
    <fx:Metadata>
        [Style(name="cornerRadius", inherit="no", type="uint")]
    </fx:Metadata>
</s:TextInput>

To use,

<local:MyExtendedTextInput cornderRadius="8" />

In the future you won't have to declare the CSS.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文