如何在 Flex 4 TextInput 组件上设置圆角半径
如何获取 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
创建自定义皮肤(可能通过复制 Spark TextInputSkin)并添加带有圆角的边框图形,如下所示:
如果您想要更特殊的圆角,您还可以使用这些属性:
默认的 TextInputSkin 不允许圆角,因此有没有可以在 TextInput 上设置的样式来执行此操作。所以,不,除了创建自定义皮肤类之外没有其他方法。
Create a custom skin (possibly by copying spark TextInputSkin) and add a border graphic with rounded corners, like this:
If you want more special rounded corners you can also use these attributes:
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.
您可以更进一步并使其充满活力。基于spark TextInputSkin 创建自定义TextInputSkin,并在updateDisplayList 方法中的super.updateDisplayList() 调用上方添加此代码。
在 YourTextInputSkin.mxml 中,
就是这样。你完成了!
现在要使用它添加一个 CSS 类选择器来添加一个cornerRadius样式,如下所示:
并将您的实例设置为该类,
不幸的是,您无法在MXML中的TextInput组件实例上设置cornerRadius样式。 Flex 是否应该像 HTML 标签那样支持这种类型的样式标签?皮肤中声明的样式是否应该代理到使用它们的组件?目前,如果您在 Skin 中声明了样式并尝试在组件实例上使用它,即使在 CSS 中声明该样式和任何其他样式都是有效的,Flex 编译器也会抛出错误。如果 UIComponents 有一个可以让您设置样式的样式代理对象怎么样?无论如何,我离题了。
如果除了前面的方法之外,您还想在 TextInput 实例上使用该样式,您可以通过扩展 TextInput 并向其中添加cornerRadius 样式元数据来实现。您还可以在使用时设置 SkinClass(内联或在库中的 defaults.css 文件中)。
像这样的东西:
要使用,
将来您将不必声明 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,
That's it. You're done!
Now to use it add a CSS class selector to add a cornerRadius style like so:
And set your instance to the class,
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:
To use,
In the future you won't have to declare the CSS.