Initializer

init(_:)

Creates a label representing the configuration of a style.

Declaration 宣言

init(_ configuration: LabelStyleConfiguration)
Available when Title is LabelStyleConfiguration.Title and Icon is LabelStyleConfiguration.Icon.

Parameters パラメータ

configuration

The label style to use.

Discussion 議論

You can use this initializer within the makeBody(configuration:) method of a LabelStyle instance to create an instance of the label that’s being styled. This is useful for custom label styles that only wish to modify the current style, as opposed to implementing a brand new style.

For example, the following style adds a red border around the label, but otherwise preserves the current style:


struct RedBorderedLabelStyle: LabelStyle {
    func makeBody(configuration: Configuration) -> some View {
        Label(configuration)
            .border(Color.red)
    }
}

See Also 参照

Creating a Label from a Configuration