Flex 自定义按钮组件 [英] Flex custom button component

查看:32
本文介绍了Flex 自定义按钮组件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望我的自定义按钮看起来像下面的按钮示例.更具体地说,我希望按钮的宽度由标签中最大单词的宽度确定(即在我的示例中为Elongated"的宽度).标签必须环绕,而不是截断.我只想要图标顶部边缘和按钮顶部边缘之间的一个像素.我已经尝试了很多东西,但到目前为止都无济于事.我已将水平间隙和垂直间隙减少到零并将填充减少到零.但还是什么都没有.请帮忙.

I want my custom button to look like the button sample below. More specifically, I want the width of the button to be determined by the width of the largest word in the label (i.e. width of "Elongated" in my example). The label must wrap, not truncate. And I want only one pixel between the top edge of the icon and my button's top edge. I have tried lots of things but to no avail so far. I have reduced the horizontalGap and verticalGap to zero and padding to zero. But still nothing. Please help.

这是我现在所拥有的:

<mx:Button  top="0" cornerRadius="2" paddingLeft="0" paddingRight="0" leading="0" letterSpacing="0" paddingTop="0" paddingBottom="0" verticalGap="0" horizontalGap="0" textAlign="center" labelPlacement="bottom" icon="{MyIcon}" height="60" width="75" label="Elongated Label" fontSize="10" />

推荐答案

那一点都不简单.

您需要创建自己的按钮,

You will need to create your own button,

public class Mybutton extends Button {...}

覆盖 createChildren 并将用于标签的 IUITextField 的自动换行设置为 true.

override createChildren and set the word wrap of the IUITextField used for the label to true.

覆盖测量并使用您自己的线条度量来确定按钮的宽度.如果你做对了,按钮就会正确地显示出来.

override measure and use your own line metrics to determine the width that the button should be. If you get the measure right, the button will lay itself out properly.

这篇关于Flex 自定义按钮组件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆