拨开荷叶行,寻梦已然成。仙女莲花里,翩翩白鹭情。
IMG-LOGO
主页 文章列表 如果在AS3中只剩下1行,如何使动态文本移动到垂直中心

如果在AS3中只剩下1行,如何使动态文本移动到垂直中心

白鹭 - 2022-03-01 2164 0 0

如果只剩下 1 行,有没有办法将动态文本多行移动到中心,因为无法在属性面板中调整垂直中心。

图片 3 行文本和 1 行文本

uj5u.com热心网友回复:

没有默认选项,但您可以模拟它。

// Let's assume this is your TextField you need to v-align.
var TF:TextField;

// Lets also assume that TextField is still in its original place.
// Record its upper Y-coordinate and height.
var atop:Number = TF.y;
var aheight:Number = TF.height;

// These lines instruct the TextField to adjust its lower
// border so that it exactly fits the text inside.
TF.wordWrap = true;
TF.autoSize = TextFieldAutoSize.LEFT;

// Now, math time.
// The difference between original height and new (autosized) height.
var adiff:Number = aheight - TF.height;

// To vertically position the resized TextField into the center of its original
// place, you need to shift it down by half of the height difference.
// It actually works if new height is larger than original too:
// the "adiff" value will be negative and it still works out.
TF.y = atop   adiff / 2;
标签:

0 评论

发表评论

您的电子邮件地址不会被公开。 必填的字段已做标记 *