Categories
Uncategorized

SwiftUI Label with icon trailing

A quick snippet of code to show you how to create a SwiftUI Label() that has the icon at the end instead of in front.

// Make a struct that conforms to the LabelStyle protocol,
//and return a view that has the title and icon switched in a HStack
struct TrailingIconLabelStyle: LabelStyle {
    func makeBody(configuration: Configuration) -> some View {
        HStack {
            configuration.title
            configuration.icon
        }
    }
}

//Usage
Label("Lightning", systemImage: "bolt.fill").labelStyle(TrailingIconLabelStyle())

Leave a Reply

Your email address will not be published. Required fields are marked *