How to use the Feathers
Label component is for displaying text. It uses a text renderer.
First, let's create a
Label control, give it some text to display, and add it to the display list:
The text may be wrapped if it is too long to fit on one line:
wordWrap property to
true to enable wrapping.
A number of styles may be customized on a label, including the font styles, the background skin, and padding. For full details about which properties are available, see the
Label API reference. We'll look at a few of the most common ways of styling a label below.
The font styles of the label may be customized using the
Pass in a
starling.text.TextFormat object, which will work with any type of text renderer.
If the label should use different font styles when it is disabled, you may set the
disabledFontStyles property too:
Let's give the label a background skin that stretches to fill the entire width and height of the label. In the following example, we pass in a
starling.display.Image, but the skin may be any Starling display object:
It's as simple as setting the
We can give the label a different background when it is disabled:
backgroundDisabledSkin is displayed when the label is disabled. If the
backgroundDisabledSkin isn't provided to a disabled label, it will fall back to using the
backgroundSkin in the disabled state.
Similar to many Feathers components, a
Label provides several properties to add padding around its content:
If all four padding values should be the same, you may use the
padding property to set them all at once:
Change the text renderer
By default, a
Label will use the global
FeathersControl.defaultTextRendererFactory() to create its text renderer. If you want to change the type of text renderer used by an individual
Label, you can provide a custom factory:
textRendererFactory property is not
null, it will be used instead of
fontStyles property will work with any type of text renderer.