skip to Main Content

On the right panel editor, there are all the characteristics from the button. But I want to know if there is an option to round the corners of the button in this panel.

right panel for Xcode

2

Answers


  1. In recent versions of iOS a button just shows the text.

    It doesn’t pay attention to the corner radius. If you set the background color to something other than transparent then it gets filled with that color.

    If you want a colored rounded rectangle, set the background color, and go to the identity inspector and add an entry under "user defined runtime attributes" with a key of "layer.cornerRadius" and a number value of 5.

    Login or Signup to reply.
  2. You could extend UIButton and use @IBInspectable to be able to set the corner radius more comfortably. I added some math so that the Button can be at max a circle and always looks pleasing. @IBDesignable is used that the button is able to render nicely in the Storyboard.

    @IBDesignable
    public class CornerRadiusButton: UIButton {
    
        @IBInspectable
        var cornerRadius: CGFloat = 0 {
            didSet {
                cornerRadius = (cornerRadius > 100) ? 100 : cornerRadius
                let max = self.bounds.size.width * 0.5
                self.layer.cornerRadius = max * cornerRadius/100
            }
        }
    }
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search