How do you set the correct width of a dynamic UITextField before assigning text?

In Flex 3.2, I create a UITextField and then measure the text that I am going to assign to this property of the text field. Then I use these metrics to set the size of the field. However, the estimated width is not wide enough to fit the text. Is there a different order to achieve the correct measurement, or am I seeing a problem with the measureText () function? How can I get accurate results?

// UITextField 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;
+3
source share
2 answers

I had all kinds of problems with measuring the width and height of text fields. It looks like you just want to automate textField. You tried:

uiTextField.autoSize = TextFieldAutoSize.LEFT;

???

+4

, Flex , textWidth. , Flex. , :

0

Source: https://habr.com/ru/post/1703374/


All Articles