swiftPunk
swiftPunk

Reputation: 1

How we can change label of Button to Bold or italic?

I got this Button Which I Like change label of it to Bold or Italic, I know it is easy with defining Text, but I want to know how we can do this without Text?

Button("Tap me!") { print("Hello, World!") }

Upvotes: 1

Views: 973

Answers (1)

Asperi
Asperi

Reputation: 258267

You can do any styling with custom button style, like below:

Button("Tap me!") { print("Hello, World!") }
    .buttonStyle(BoldButtonStyle())

and custom style

struct BoldButtonStyle: ButtonStyle {
    func makeBody(configuration: Self.Configuration) -> some View {
        configuration.label.font(Font.body.bold())
    }
}

In similar way you can add colors, hightlight, etc.

Updated: if it is only font, then just

Button("Tap me!") { print("Hello, World!") }
   .font(Font.body.bold())

Upvotes: 2

Related Questions