Label¶

A view that combines an SF Symbol icon with a text title, following Apple's Human Interface Guidelines. Labels are commonly used in navigation items, list rows, and menu entries. For full control over appearance, custom views can be provided instead of strings.
Constructor¶
nib.Label(
title=None,
icon=None,
title_view=None,
icon_view=None,
style=None,
**modifiers,
)
Parameters¶
| Parameter | Type | Default | Description |
|---|---|---|---|
title |
str |
None |
Text string displayed as the label title. For custom styling, use title_view instead. |
icon |
str |
None |
SF Symbol name for the icon (e.g., "gear", "star.fill", "bell.badge"). For custom icons, use icon_view instead. |
title_view |
View |
None |
Custom view to use as the title. Alternative to title. |
icon_view |
View |
None |
Custom view to use as the icon. Alternative to icon. |
style |
LabelStyle | str |
None |
Determines which parts of the label are shown. Options: LabelStyle.automatic, LabelStyle.titleOnly, LabelStyle.iconOnly, LabelStyle.titleAndIcon. |
**modifiers |
Common view modifiers: padding, background, foreground_color, font, opacity, etc. |
Examples¶
Basic label with icon¶
![]()
import nib
def main(app: nib.App):
app.title = "Sidebar"
app.icon = nib.SFSymbol("sidebar.left")
app.height = 200
app.build(
nib.VStack(
controls=[
nib.Text("Library", font=nib.Font.HEADLINE),
nib.Label("Recents", icon="clock"),
nib.Label(
"Favorites", icon="star.fill", foreground_color=nib.Color.YELLOW
),
nib.Label("Shared", icon="person.2"),
nib.Label("Trash", icon="trash", foreground_color=nib.Color.SECONDARY),
],
spacing=10,
padding=20,
alignment=nib.Alignment.LEADING,
)
)
nib.run(main)
Label style variations¶

import nib
def main(app: nib.App):
app.title = "Label styles"
app.icon = nib.SFSymbol("tag")
def row(name, style):
return nib.HStack(
controls=[
nib.Text(name, foreground_color=nib.Color.SECONDARY, width=130),
nib.Label("Wi-Fi", icon="wifi", style=style),
]
)
app.build(
nib.VStack(
controls=[
nib.Text("LabelStyle", font=nib.Font.HEADLINE),
row("TITLE_AND_ICON", nib.LabelStyle.TITLE_AND_ICON),
row("TITLE_ONLY", nib.LabelStyle.TITLE_ONLY),
row("ICON_ONLY", nib.LabelStyle.ICON_ONLY),
],
spacing=10,
padding=20,
alignment=nib.Alignment.LEADING,
)
)
nib.run(main)
Related¶
- SFSymbol
- Text
- Image
- Style Enums:
LabelStyle