跳转至
Structure

TitleOnlyLabelStyle

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

Declaration

struct TitleOnlyLabelStyle : LabelStyle

Overview

Use this label style to display a Label with a title 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.

Availability

iOS 14.0+

macOS 11.0+

tvOS 14.0+

watchOS 7.0+

Topics


Initializer

init() Creates a title-only label style.


Instance Method

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


Type Alias

Body A view that represents the body of a label.