Flex 4 - 自动调整字体大小以适应组件宽度
我正在寻找一种方法来创建一个标签(文本区域即可),我可以自动调整字体大小,使文本适合宽度。
为了使它更清楚一点,我了解 autosize 属性将允许组件增加其宽度,以便所有文本都可见,我正在寻找与此相反的内容。假设我有一个 200px 宽度的标签,并且我有大约 300px 的文本,标签应该降低字体大小,以便它可以在 200px 区域内显示。
我已经搜索遍了,我能找到的只是一个标题文本字段的 AS3 示例(http://livedocs.adobe.com/flex/3/html/help.html?content=Working_with_Text_22.html),但我找不到我一生都在想如何让它在 Flex 4 自定义组件之类的环境中工作,
请帮助我???
I am looking for a way to have a lable (a textarea will do) that I can have adjust the font-size automatically so that the text fits the width.
To make it a bit clearer I understand the autosize property will allow the component to increase it's width so that all the text is visible, I am looking for sort of the opposite of this. Say i have a 200px width label and i have text that spans about 300px, the lable should lower the font-size so that it can be shown within the 200px area.
I've searched all over and all I could find was an AS3 sample for a headlinetextfield (http://livedocs.adobe.com/flex/3/html/help.html?content=Working_with_Text_22.html) but i couldnt for the life of me figure out how to get this to work in a Flex 4 custom component sort of environment
PLEASE HELP me???
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这取决于您想要的准确度。
正如 Flextras 所指出的,为了完美贴合宽度,您必须进行测量。对于 Flex,您可以在 updateDisplayList() 上实现。
如果您正在寻找更简单的方法,您可以尝试优化比率并使用数据绑定。
例如,如果 20 的字体大小适用于 200 像素宽度,则使用该比例:
这不是最佳方法,但可能会为您赢得时间来研究线条指标。
This depends on the level of accuracy you want.
As Flextras indicated, for width to fit perfectly you must measure. Per Flex, you'd implement on updateDisplayList().
If you're looking for something easier, you could try to optimize a ratio and use data binding.
Like, if font size of 20 worked for 200 pixels width, than use that ratio:
This is not an optimal approach, but might buy you time to look into line metrics.