跳转至
Structure

IconOnlyLabelStyle

A label style that only displays the icon of the label.

Declaration

struct IconOnlyLabelStyle : LabelStyle

Overview

Use this label style to display a Label with an icon only.

This is one of 3 default label styles. These are structs that conform to the LabelStyle protocol by implementing the makeBody(configuration:) function internally, so you don't have to do it yourself.

These are the default styles:

All 3 styles have only one initializer, which takes no parameters.

To use a LabelStyle, pass it to a Label's labelStyle(_:) modifier:

struct ContentView: View {
    var body: some View {
        VStack {
            Label("Banana", systemImage: "suit.heart.fill")
                .labelStyle(DefaultLabelStyle())
            Label("Banana", systemImage: "suit.heart.fill")
                .labelStyle(IconOnlyLabelStyle())
            Label("Banana", systemImage: "suit.heart.fill")
                .labelStyle(TitleOnlyLabelStyle())
        }
        .font(.title)
    }
}
A view displaying a VStack with three labels; the first reads as "<3 Banana" and is of default style, the second reads as "<3" and is of icon only style, and the third reads as "Banana" and is of title on style.

  • Note: The title of the label is still used for non-visual descriptions, such as VoiceOver.

Availability

iOS 14.0+

macOS 11.0+

tvOS 14.0+

watchOS 7.0+

Topics


Type Alias

Body A view that represents the body of a label.


Instance Method

makeBody(configuration:) Creates a view that represents the body of a label.


Initializer

init() Creates an icon-only label style.