Tuesday, December 20, 2011

Aligning Text in Spark Label

I have been asked this question quite a few times, so I thought I'd place this in here too... :)

So how does one align text in a Spark Label.

There are 2 styles one needs to set based on how the alignment is required to be. "textAlign" and "verticalAlign".

textAlign
This sets the horizontal alignment of the text in the Label. This can be set to one of the 3 values viz., 
"start", "center", "end".
By default the textAlign is set to "start" in a Spark Label.

This also depends on another style in Label called, "direction". The "direction" style sets the direction of the text in the Label,
"ltr" (Left To Right) as in regular English
"rtl" (Right To Left) as in Arabic/Urdu

When the direction is set to "ltr", "start" indicates the left end of the label and "end" indicates the right end of the label. It is vice versa in case the direction is set to "rtl"

verticalAlign
The "verticalAlign" style aligns the text vertically in the Label. This can be set to one of the 5 values viz,
"top", "middle", "bottom", "justify", "inherit"

The default value for a Spark Label is "top".