I have 4 labels with have the same dimensions (width="200", maxHeight="100")
and get 4 different texts for the labels.
At least I want that every text fits into the labels dimensions and that all
texts have the same fontSize (the fontsize of the label with most text in
it).
Currently I get the minimim size by testing the maximum fontSize for every
label, compare them and taking the smallest.
Is there a better way to get the maximum font size which will fit to a label
as below?
That's my way to get the maximum font size inside the labels parent
component (s:Group):
// somewhere in updateDisplayList
textLabel.setStyle("fontSize", 52);
while(isResizeNecessary())
{
setSmallerFontSizeAndRevalidate();
}
// other methods
private function isResizeNecessary():Boolean
{
var FONT_SIZE_STEPS:int = 2;
var isTextLabelToHeight:Boolean =
textLabel.getPreferredBoundsHeight() >
getMaxHeightForTextLabel();
var isTextDownscaleable:Boolean =
textLabel.getStyle("fontSize") >
FONT_SIZE_STEPS;
return isTextLabelToHeight && isTextDownscaleable;
}
private function setSmallerFontSizeAndRevalidate():void
{
var FONT_SIZE_STEPS:int = 2;
textLabel.setStyle("fontSize",
textLabel.getStyle("fontSize") -
FONT_SIZE_STEPS);
textLabel.invalidateProperties();
textLabel.invalidateSize();
textLabel.invalidateDisplayList();
textLabel.validateNow();
invalidateDisplayList();
}
--
View this message in context:
http://apache-flex-users.2333346.n4.nabble.com/Scale-font-size-of-text-to-fit-into-a-label-with-fixed-dimensions-tp12424.html
Sent from the Apache Flex Users mailing list archive at Nabble.com.