SwiftUI: apply background color to rounded rectangle

Viewed 4876

I would like to create a button with a rounded rectangle view with a border, and a background color.

I wrote this so far :

Button(action: {
}, label: {
    Text("TAP ME")
        .foregroundColor(Color.blue)
})
.frame(height: 50)
.frame(maxWidth: .infinity)
.overlay(
    RoundedRectangle(cornerRadius: 50, style: .continuous)
        .strokeBorder(Color.blue, lineWidth: 1)                
)

I tried to add .background(Color.red) at many different places, but here is what I get everytime:

enter image description here

What to do here?

Thank you for your help

1 Answers

As far as I understood your needs, here is a solution

demo

Button(action: {
}, label: {
    Text("TAP ME")
        .foregroundColor(Color.blue)
})
.frame(height: 50)
.frame(maxWidth: .infinity)
.background(
    RoundedRectangle(cornerRadius: 50, style: .continuous).fill(Color.red)
)
.overlay(
    RoundedRectangle(cornerRadius: 50, style: .continuous)
        .strokeBorder(Color.blue, lineWidth: 1)
)
Related