Structure¶
LabelStyleConfiguration¶
The properties of a label.¶
Declaration¶
struct LabelStyleConfiguration
Overview¶
Use this structure to access the properties of a Label when creating your own LabelStyles. A LabelStyleConfiguration has two properties:
- LabelStyleConfiguration/title: The Label's Text part.
- LabelStyleConfiguration/icon: The Label's Image part.
A parameter of this type called configuration is passed to the one required function of the LabelStyle protocol: makeBody(configuration:).
In the example below, we use the configuration parameter in the makeBody(configuration:) function to create our own custom LabelStyle
struct MyLabelStyle: LabelStyle {
let color: Color
func makeBody(configuration: Configuration) -> some View {
VStack {
configuration.title
configuration.icon
.foregroundColor(color)
}
}
}
struct ContentView: View {
var body: some View {
VStack {
Label("Banana", systemImage: "suit.heart.fill")
.labelStyle(MyLabelStyle(color: .yellow))
Label("Apple", systemImage: "suit.heart.fill")
.labelStyle(MyLabelStyle(color: .red))
}
.font(.title)
}
}

Availability¶
iOS 14.0+
macOS 11.0+
tvOS 14.0+
watchOS 7.0+
Topics¶
Structure¶
Icon A type-erased icon view of a label.
Title A type-erased title view of a label.
Instance Property¶
icon A symbolic representation of the labeled item.
title A description of the labeled item.