uilabel (App Designer)

Create label component

Use only with App Designer or figures created with the uifigure function. When using GUIDE or the figure function, create labels using uicontrol.

Syntax

  • lbl = uilabel
  • lbl = uilabel(parent)
    example
  • lbl = uilabel(___,Name,Value)
    example

Description

lbl = uilabel creates a label component with the text 'Label' in a new UI figure window and returns a label object.

example

lbl = uilabel(parent) specifies the parent object in which to create the label. The parent object must be a UI figure window, or a tab, panel, or button group within a UI figure window.

example

lbl = uilabel(___,Name,Value) specifies label properties using one or more Name,Value pair arguments. Use this option with any of the input argument combinations in the previous syntaxes.

Input Arguments

collapse all

Parent object of the label, specified as a figure, panel, tab, or button group object.

The parent object must be either a figure created using the uifigure function, or a tab, panel, or button group within such a figure.

Name-Value Pair Arguments

Specify optional comma-separated pairs of Name,Value arguments. Name is the argument name and Value is the corresponding value. Name must appear inside single quotes (' '). You can specify several name and value pair arguments in any order as Name1,Value1,...,NameN,ValueN.

Example: 'Text','Sum:' specifies the label displays the text Sum:.

The properties listed here are a subset of the available properties. For the full list, see .Label (App Designer) Properties.

collapse all

Label characters, specified as a character vector or a cell array of character vectors. Use a cell array of character vectors to specify a multiline label.

Alternatively, use the sprintf function to create formatted text containing line breaks and other special characters.

text = sprintf('%s\n%s','Line 1','Line 2');
label = uilabel('Text',text,'Position',[100 100 100 32]);

If you specify text as a character vector without using sprintf, MATLAB® will not automatically interpret control sequences like "\n".

text = 'Line 1\nLine2'
label = uilabel('Text',text,'Position',[100 100 100 32])

Example: 'Threshold'

Example: {'Threshold' 'Value'}

Label location and size, relative to the parent, specified as the vector [left bottom width height]. This table describes each element in the vector.

ElementDescription
leftDistance from the inner left edge of the parent container to the outer left edge of the label
bottomDistance from the inner bottom edge of the parent container to the outer bottom edge of the label
widthDistance between the right and left outer edges of the label
heightDistance between the top and bottom outer edges of the label

All measurements are in pixel units.

    Note:   The Position values are relative to the drawable area of the parent container component (UI figure, button group, panel, or tab). The drawable area of a container component is the area inside its borders, excluding the title bar.

Example: [100 100 100 20]

Examples

collapse all

f = uifigure;
label = uilabel(f);

Specify a panel as the parent object for a label.

fig = uifigure;
pnl = uipanel(fig);
lbl = uilabel(pnl);

Create a default label.

fig = uifigure;
lbl = uilabel(fig);

Change the label text and font size.

lbl.Text = 'Result';
lbl.FontSize = 14;

The label is clipped because the current label size is too small for the new text at the new font size.

Determine the current label size by getting the third and fourth elements of the Position property value.

size = lbl.Position(3:4)
size =

    31    15

Change the label size to accommodate the new text.

lbl.Position(3:4) = [62 22];

Introduced in R2016a

Was this topic helpful?