Round button corners in Swift

I need to round a filled in button in Swift. My button was added, and filled, in Storyboard.


Here's some of the things I've tried, none of which work:

button.layer.cornerCurve = .continuous
button.layer.cornerCurve = .continuous
     button.clipsToBounds = true

The first one works in another app of mine, but won't work here.


I'm quite confused at the moment so any help would be hugely appreciated!


Thank you all so much in advance, and I hope you're all well.

Accepted Reply

My button was added, and filled, in Storyboard.

How have you set your button filled in the storyboard? There's no setting named `filled`.


(And your line 01. and line 02. are the same. Any mistakes?)


As far as I tried a button with setting Background in Xcode 11.5, this line was enough to get a rounded filled button:

        button.layer.cornerRadius = 10.0


Please show more detailed settings of your button if this does not work as you expect.

Replies

What does not work ?

- what do you get ?

- what did you expect ?


Please show more code. Or replicate what you did in other app😉.


I tested in an app:

button is an IBOutlet for a UIButton


          if #available(iOS 13.0, *) {
               button.layer.borderWidth = 3
               button.layer.borderColor = UIColor.green.cgColor
               button.layer.cornerCurve = .continuous
          } else {
               // Fallback on earlier versions
          }



It works as expected.


Have you defined the color and width of border ?

My button was added, and filled, in Storyboard.

How have you set your button filled in the storyboard? There's no setting named `filled`.


(And your line 01. and line 02. are the same. Any mistakes?)


As far as I tried a button with setting Background in Xcode 11.5, this line was enough to get a rounded filled button:

        button.layer.cornerRadius = 10.0


Please show more detailed settings of your button if this does not work as you expect.

Thank you so much, that worked!! It's practically the same as another solution I tried that didn't work, but whatever, at least it's working now.


Have a great day!