开发者

Reset a flex label width to "auto" after setting an explicit width?

Once I've set either the width or percentWidth property on a flex label, is there a way to reset the width to its default (i.e., the width of the text plus padding)?

I'm using the label as a renderer. In some cases, I'd like it to automatically size to the text, and in other cases, I'd like it to be a percentage width of its container. Obviously, I could use two separate l开发者_如何学JAVAabels, one for each of the above cases, but I'm curious if it's possible to reset the label to its default behavior.


label.width = NaN;
//not sure if the following lines are required
label.invalidateSize();
label.width = label.measuredWidth;

From flex livedocs

When you set a specific height and width of a component, Flex does not call the measure() method, even if you explicitly call the invalidateSize() method. That is, Flex only calls the measure() method if the explicitWidth property or the explicitHeight property of the component is NaN.


Set the width to undefined:

yourLabelId.width = undefined;

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜