UserGuide

iOS Label

From Xojo Documentation

The label control displays text on the view. This is often used for displaying information or providing labels to other controls.

Below are commonly used properties. Refer to iOSLabel in the Language Reference for the complete list.

Properties

LineBreakMode

Uses the iOSLineBreakMode enumeration to indicate how text will wrap (or be truncated) when it is too long to fit in the label.

Text

This is the text that appears in the label.

TextAlignment, TextColor, TextFont

These properties change the alignment, color and size of the text.

Visible

A boolean that indicates if the Label is visible when your app runs.

Usage

Generally you will like set up the text for your labels using the Inspector. But you can also set the text using code:

NameLabel.Text = "Enter your name:"

You may have situations where the label should not yet be visible. You can set its Visible property to OFF in the Inspector and then turn it on in your app when appropriate:

If showName Then
NameLabel.Visible = True
End If

Labels are will automatically show multiple lines for lengthy text if you increase the height. By default the text wraps using word wrapping. But you can change the LineBreakMode property to use any of these methods for wrapping and/or truncating:

  • BreakByWordWrapping (default): Words are not split when text wraps to a new line.
  • BreakByCharWrapping: Words may be split whe text wraps to a new line.
  • BreakByClipping: Text is clipped at the end, possibly mid-character.
  • BreakByTruncatingHead: Ellipses appear at the beginning of the text if it cannot all fit.
  • BreakByTruncatingTail: Ellipses appear at the end of the text if it cannot all fit.
  • BreakByTruncatingMiddle: Ellipses appear in the middle of the text if it cannot all fit.

Refer to the iOSLineBreakMode enumeration for more details on these values.

Changing the formatting of a label is done using the TextAlignment, TextColor and TextFont properties. Alignment can be Left, Center, Right, Justified and Natural. To change the alignment you use the iOSTextAlignment enumeration. This centers the text in the label:

NameLabel.TextAlignment = iOSTextAlignment.Center

You can set the color to be any Color with the TextColor property:

NameLabel.TextColor = Color.Blue

To change the font, you use the TextFont property in conjunction with the iOSFont class.

See Also

iOSLabel, iOSFont classes; UserGuide:iOS UI topic