【问题标题】:calculating Spark TextArea width计算 Spark TextArea 宽度
【发布时间】:2010-11-03 10:54:28
【问题描述】:
我将 spark TextArea 视为文本输入(通过设置 heightInLines="1")。 TextArea 是 mxml 组件的一部分,我想在文本更改时调整组件的大小。
我无法使用 textArea.measureaText(textArea.text) 获取线度量并使用它。我收到此错误“参数 antiAliasType 必须为非空。”
有什么方法可以获取在运行时为特定字符串或特定 TextFlow 消耗的 TextArea 的宽度?
【问题讨论】:
标签:
apache-flex
width
textarea
flex-spark
【解决方案1】:
有点难看,但对我有用:
var uiText:UItextField = new UITextField();
// if you have custom text style on the TextArea then set it the same of this uitextfield
uiText.setTextFormat("bla bla bla");
uiText.text = "This is the text that I want the size for";
var textW:Number = uiText.textWidth;
var textH:Number = uiText.textHeight;
// then we need to consider also the border of the text area and the paddings
// try read the padding values and border sizes using getStyle(...)
myTextArea.width = textW+2*borderW+paddingL+paddingR;
myTextArea.height = textH+2*borderH+paddingT+paddingB;
应该就是这样