开发者

left-justify textfield without resizing

I would like to set a fixed width for an input textfield with an embedded font. I would like to have the option to left-, right-, or center-justify the text. This is proving difficult.

If I set myTextField.autoSize = TextFieldAutoSize.LEFT;, I get left-justified text, but the textfield width changes with each keystroke. Same trade-off with TextFieldAutoSize.RIGHT and TextFieldAutoSize.CENTER.

Now, if I use TextFieldAutoSize.NONE, then I can fix the width and height of my textfield, making it the size I want... but the cursor is always blinking in the middle of the textfield. Wha开发者_Python百科t's the secret to justifying that cursor to the left [or right] and the textfield staying the size I initially set it to?


You should use the TextFormat classes align property with the TextFormatAlign class for paragraph alignment. The TextField autoSize changed the bounding box size of the TextField.

So you would do something like:

myTextField.autoSize = TextFieldAutoSize.NONE; // This is the default anyway.
var myTextFormat:TextFormat = new TextFormat();
myTextFormat.align = TextFormatAlign.LEFT;
myTextField.defaultTextFormat = myTextFormat;
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜