Specify SwiftUI button's size outside ButtonStyle

Viewed 13

Is it possible to configure button's colours, fonts in ButtonStyle and adjust the frame size outside?

Having the simplest style with the configured colours:

struct PrimaryButtonStyle: ButtonStyle {
    func makeBody(configuration: Configuration) -> some View {
            configuration.label
                .foregroundColor(.white)
                .background(Color.green)
    }
}

I want to use something like that, but adjusting the frame only:

Button("Login") {
}
.frame(width: 250)
.buttonStyle(PrimaryButtonStyle())

The current result is the following:

enter image description here

Sure, I can pass the width value in the style, but want to achieve it more natural in SwiftUI.

0 Answers
Related