开发者

Flex 4 - Auto adjust font size to fit component width

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 sp开发者_运维问答ans 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???


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:

<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
               xmlns:s="library://ns.adobe.com/flex/spark"
               xmlns:mx="library://ns.adobe.com/flex/mx">

    <s:Label text="Size as ratio"
             fontSize="{(20 / 200) * width}" />

</s:Application>

This is not an optimal approach, but might buy you time to look into line metrics.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜