Black Friday 2024 deal: 30% off our Swift and SwiftUI books! Learn more ...Black Friday 2024 deal:30% off our Swift and SwiftUI books >>
Quick Tip Icon
Quick Tip

Customize ShareLink appearance with view modifiers

While we can provide a fully custom view as a label of the ShareLink in SwiftUI, we can also customize the default appearance with view modifiers instead.

The default style of the ShareLink adapts to its context, but changing its appearance can be useful when we are designing a custom toolbar, for example.

All the style changes that we can apply to a regular SwiftUI Label view can be applied to the ShareLink as well. We can set the label style to only show the icon or the text, adjust the image scale or choose a symbol variant.

ShareLink(item: url)
    .labelStyle(.iconOnly)
    .imageScale(.large)
    .symbolVariant(.fill)

Since all of these values are set in the environment, SwiftUI will read them internally and apply to the label of the ShareLink for us.

Here is how the default appearance of the link gets updated with our modifications.

Screenshots showing the default share link with icon and text and the customized one with only the icon
Swift Gems by Natalia Panferova book coverSwift Gems by Natalia Panferova book cover

Black Friday 2024 offer: 30% off!$35$25

100+ tips to take your Swift code to the next level

Swift Gemsby Natalia Panferova

  • Advanced Swift techniques for experienced developers bypassing basic tutorials
  • Curated, actionable tips ready for immediate integration into any Swift project
  • Strategies to improve code quality, structure, and performance across all platforms
Black Friday 2024 offer: 30% off!

100+ tips to take your Swift code to the next level

Swift Gems by Natalia Panferova book coverSwift Gems by Natalia Panferova book cover

Swift Gems

by Natalia Panferova

$35$25