TEAM LICENSES: Save money and learn new skills through a Hacking with Swift+ team license >>

SOLVED: Reduce the space between a Label's title and icon

Forums > SwiftUI

Is there a way to reduce the default padding inside the Label view?

2      

Hi! You can create custom labelstyle similar to this.

struct ContentView: View {
    var body: some View {
       Label("This is my title", systemImage: "star.circle.fill")
            .labelStyle(CustomLabel(spacing: -2))
    }
}

struct CustomLabel: LabelStyle {
    var spacing: Double = 0.0

    func makeBody(configuration: Configuration) -> some View {
        HStack(spacing: spacing) {
            configuration.icon
            configuration.title
        }
    }

2      

@ygeras Won't that mess up with the accessibility?

2      

I don't think so, you are just changing spacing. This is more decorative adjustment, but in any case test how it behaves.

2      

Hacking with Swift is sponsored by String Catalog.

SPONSORED Get accurate app localizations in minutes using AI. Choose your languages & receive translations for 40+ markets!

Localize My App

Sponsor Hacking with Swift and reach the world's largest Swift community!

Reply to this topic…

You need to create an account or log in to reply.

All interactions here are governed by our code of conduct.

 
Unknown user

You are not logged in

Log in or create account
 

Link copied to your pasteboard.