Kar534
Kar534

Reputation: 127

Trying to give a border a corner radius in swiftui

I am trying to create a border around a RoundedRectangle where the border has a cornerRadius of 25. Here is the code I have.

             RoundedRectangle(cornerRadius: 25)
                .fill(Color.white)
                .frame(width: 290, height: 315)
                .border(Color("Dark Text"), width: 3)
                .cornerRadius(25)

From this code the the rectangle has a cornerRadius of 25 but the border matches the frame. How would I get the border to have a cornerRadius of 25?

Upvotes: 2

Views: 2383

Answers (1)

Simon
Simon

Reputation: 1870

This should do:

RoundedRectangle(cornerRadius: 25)
            .stroke(Color.black, lineWidth: 5) // used for border
            .frame(width: 290, height: 315)

If you want to use multiple modifiers it sometimes won't let you use the stroke. E.g. with fill. In that case use a overlay like this:

RoundedRectangle(cornerRadius: 25)
            .fill(Color.white)
            .frame(width: 290, height: 315)
            .overlay(
                RoundedRectangle(cornerRadius: 25)
                    .stroke(Color.black, lineWidth: 5)
            )

Upvotes: 5

Related Questions