Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Make a SwiftUI button with style .bordered expand to full width

I’m trying to make a SwiftUI button with .buttonStyle(.bordered) have the full width of the VStack it’s in. Here’s my button code:

Button("Save", action:saveUser)
    .frame(maxWidth:.infinity)
    .buttonStyle(.borderedProminent)

In the preview, I can see the actual frame is the full width of its container, but the background provided by the buttonStyle is not:

Button background is not full width

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

How can I make the border provided the button style also be full width?

>Solution :

Use this way to make a full-width button.

Button(action: {
    saveUser()
}) {
    Text("Save").frame(minWidth: 0, maxWidth: .infinity)
}.buttonStyle(.borderedProminent)
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading