在Flex 3.2中,我正在创建一个UITextField,然后测量我要分配给该字段的text属性的文本。然后,我使用这些指标来设置字段的大小。但是,计算出的宽度不足以容纳文本。是否有不同的顺序来实现正确的测量,或者我看到measureText()函数有问题?我怎样才能得到准确的结果?
// UITextField's default size appears to be 100x100
// Measure the text then set width and height
var tf:UITextFormat = uiTextField.getUITextFormat();
var tlm:TextLineMetrics = tf.measureText(this.labelText);
// Text within the field is clipped unless 'padding' is added to the size
// Flex Documentation specifies there is a 2 px gutter on each side, so
// the expected padding would be 4 px. However, clipping occurs, for
// "Hello, World" up to 9 px.
uiTextField.width = tlm.width + 9;
uiTextField.height = tlm.height + 4;
uiTextField.border = true;
uiTextField.name = "uiTextField";
uiTextField.text = this.labelText;
答案 0 :(得分:4)
我之前测量textFields的宽度和高度时遇到了各种各样的麻烦。看起来你只想自动调整textField。你试过了吗?
uiTextField.autoSize = TextFieldAutoSize.LEFT;
???
答案 1 :(得分:0)
不幸的是,Flex在尝试动态获取textWidth时经常会感到非常困惑。更糟糕的是,很难可靠地捕获错误并使Flex正确更新。我发现的最佳选择: