PDA

View Full Version : How to adjust the label height based on the font chosen?


nsurendiran
09-26-2008, 10:28 AM
Hi All,

Kindly see below the code attached. If I choose the Comic Sans MS as the fontFamily in the label, the output was fine. But If I choose "Times New Roman" or "Arial" or "Courier New" as the fontFamily, I am getting lots of blankspace after the second line "HELLO HOW ARE YOU".

But my requirement was at any point of time, the space above the first line and the space after the second line should be the same.

Any help would be appreciated.
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">
<mx:Script>
<![CDATA[
public function calltext():String{
var labeldata:Array = new Array();
labeldata.push("HAI");
labeldata.push("HELLO HOW ARE YOU?");
var lasttext:String = labeldata.join("\n");
return lasttext;
}

]]>
</mx:Script>

<mx:VBox horizontalScrollPolicy="off" verticalScrollPolicy="off">
<mx:Label text="{calltext()}" height="75" fontSize="25" fontFamily="Comic Sans MS" opaqueBackground="gray" color="red" width="500"/>
</mx:VBox>
</mx:Application>


Thanks.

nsurendiran
09-29-2008, 12:48 PM
Hi all,

I got the answer from some other forum...

I think the space is always same, it is because the other fonts are comparatively smaller in nature than Comic Sans MS and the height of the Label component is fixed you are getting the gap. The font is occupying lesser space and so the rest is left blank.

Try using mx:Text instead of Label so that you need not have the height constant to render multiple line text.

thanks

rawmantick
09-29-2008, 02:04 PM
For any font there is a rule for minimum width and height to avoid text not fully getting into text frame:

txtField.width = txtField.textWidth + 4;
txtField.height = txtField.textHeight + 4;

You can retrieve text field control of label. See in docs...