Peter Tretyakov Peter Tretyakov - 1 year ago 96
iOS Question

draw func doesn't work for button from storyboard

In my app I have several

s, which I want to be with rounded corners. All of these buttons are placed in Storyboard.

I've created custom class
, which has simple override of

import UIKit

class RoundedButton: UIButton {

override func draw(_ rect: CGRect) {
self.layer.cornerRadius = 4.0


I've added this custom class to every button in Storyboard, but buttons corners are not rounded in simulator.

Thanks for any help!

Answer Source

You should instead override init

required init?(coder aDecoder: NSCoder) {
   super.init(coder: aDecoder)

   layer.cornerRadius = 4.0


if you don't use storyboard, or xib's

override init(frame: CGRect) {
   super.init(frame: frame)

   layer.cornerRadius = 4.0
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download