iOS Notes 33: How to create a circle button with colour? [Function]

Kuray Ogun
FreakyCoder Software Blog

--

Updated: Sept 20, 2020

This function let your buttons perfect circle and you can use this function as many as you want. So, you do not need to write the same code segment for every button which you want them to circle with colour.

Markdown :

func setupButtonStyle(button : UIButton, color: UIColor){
button.layer.cornerRadius = 0.5 * button.bounds.size.width
button.clipsToBounds = true
button.backgroundColor = color
}

Gist :

Ta-daa :) Your buttons are a perfect circle with your special colour with just one function.

If you have any question, ask me :)

--

--