在 Flex 3.2 中,我正在创建一个 UITextField,然后测量我将要分配给该字段的文本属性的文本。然后我使用这些指标来设置字段的大小。但是,计算出的宽度不足以容纳文本。是否有不同的顺序来实现正确的测量,或者我看到 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;