How to round corners at UIButton?

    2 answers 2

    either create it with rounded corners

    let button = UIButton(type: .roundedRect) 

    either set the corner radius

     button.layer.cornerRadius = 3 

    if you specify the radius, you can also add color and width of the border

     button.layer.borderWidth = 3 button.layer.borderColor = UIColor.red.cgColor 
    • Very helpful answer. Thank! - Igor Zexyy
    • Do not tell me how to assign a "certain color." That is, I have a color in the form of sRGB IEC61966-2.1. How to assign it? - Igor Zexyy
    • let color = UIColor(red: 0.5, green: 0.5, blue: 1, alpha: 1) - Max Mikheyenko
    • And how to assign a color from the palette (more precisely, which I myself will set there)? - Igor Zexyy
    • I wrote in the comments above how to ask any color - Max Mikheyenko
     button.layer.cornerRadius = buttonn.frame.size.height / 2 

    Universal rounding - not hardcoded cornerRadius, the button will always be oval (regardless of the size of the button)

    • And how to convey the color that I set in the palette? - Igor Zexyy