作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
这个问题不太可能对任何 future 的访客有帮助;它只与一个小的地理区域、一个特定的时间点或一个非常狭窄的情况相关,通常不适用于互联网的全局受众。如需帮助使这个问题更广泛适用,visit the help center .
10年前关闭。
我正在尝试为 AS3 中的文本字段绘制背景。
我有一个带有嵌入字体并使用 autoSize = TextFieldAutoSize.LEFT 的 TextField。我将文本分配给 TextField,然后调用 try 使用 TextField 的 textWidth 绘制一个 roundedRect。文本字段宽度始终小于实际文本宽度。
还有另一种方法可以获得实际的文本宽度吗?我做了一些快速的谷歌搜索,但我没有找到任何东西。
代码:
var tfProgramName:TextField = TextUtil.createTextField(true,"Arial",20,true);
tfProgramName.width = 100;
tfProgramName.autoSize = TextFieldAutoSize.LEFT;
tfProgramName.x = 5;
tfProgramName.y = 5;
addChild(tfProgramName);
tfProgramName.text = _program.title;
background.graphics.clear();
background.graphics.beginFill(0xFF0000,0.75);
background.graphics.drawRoundRect(0,0,tfProgramName.textWidth+10,this.height+10,5,5);
background.graphics.endFill();
最佳答案
我不能保证它会更好,但看看 TextLineMetrics它为您提供的信息比其他任何东西都多,因此这可能是您最好的选择。
关于flash - AS3 中的 TextFieldAutoSize 和 textWidth,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4963948/
这个问题不太可能对任何 future 的访客有帮助;它只与一个小的地理区域、一个特定的时间点或一个非常狭窄的情况相关,通常不适用于互联网的全局受众。如需帮助使这个问题更广泛适用,visit the h
我是一名优秀的程序员,十分优秀!