How it works
TitleOnlyLabelStyle is a label style that displays only the title of a Label, omitting its icon entirely. Use it when the icon would be redundant, distracting, or unavailable in a given context, and you want a label to read as plain text while still composing it from the same title-and-icon source. Because it conforms to LabelStyle, you apply it through the labelStyle(_:) modifier rather than constructing it directly, most conveniently through the .titleOnly convenience value.
Compose the label with both a title and an icon
TitleOnlyLabelStyle operates on a standard Label, so you still author the label with its full content even though only part will render. Here
Label("Title Only", systemImage: "star.fill")provides both a title string and an SF Symbol; the style decides what survives, letting you keep one label definition and vary its presentation by context.Apply the style with labelStyle(_:)
Label styles are applied through the
labelStyle(_:)view modifier, which takes any type conforming to LabelStyle. Attaching.labelStyle(.titleOnly)to the second label swaps in TitleOnlyLabelStyle, so SwiftUI renders that label's title alone and drops thestar.fillicon.Reach for it through the .titleOnly shorthand
Rather than writing
TitleOnlyLabelStyle(), you typically use the static.titleOnlyvalue that SwiftUI exposes on LabelStyle. The leading-dot form in.labelStyle(.titleOnly)resolves to this singleton style, keeping the call site terse and consistent with the other built-in styles like .iconOnly and .titleAndIcon.Contrast it with the inherited default
Without an explicit style, a Label uses the environment's default, which shows both title and icon — that is what the first
Label("Default Label", systemImage: "star.fill")produces here. Placing the styled and unstyled labels side by side in theVStackmakes TitleOnlyLabelStyle's effect plain: the same kind of label, with the icon suppressed.Propagate it down the view hierarchy
Because labelStyle(_:) sets a value in the environment, applying TitleOnlyLabelStyle to a container cascades to every Label beneath it. Moving
.labelStyle(.titleOnly)from the single label onto the enclosingVStackwould render all of its labels title-only, which is the idiomatic way to style a group of labels uniformly.
.labelStyle(.titleOnly) off the second Label and onto the VStack to watch both labels — including "Default Label" — lose their star.fill icons at once.Example & preview
Press Run live & edit to compile it in your browser — then edit the Swift on the left and the preview re-renders live.
struct TitleOnlyLabelStyleDemo: View {
var body: some View {
VStack(spacing: 16) {
Label("Default Label", systemImage: "star.fill")
Label("Title Only", systemImage: "star.fill")
.labelStyle(.titleOnly)
}
.padding()
}
}