User User - 2 years ago 857
Swift Question

How to create a circular button in Swift?

I want to make a circular thumbs up and thumbs down button.

Should I use a ImageView or a Button as the super class?

How would I do this in Swift?

Answer Source

Here is an example round button:

override func viewDidLoad() {

    let button = UIButton(type: .Custom)
    button.frame = CGRectMake(160, 100, 50, 50)
    button.layer.cornerRadius = 0.5 * button.bounds.size.width
    button.setImage(UIImage(named:"thumbsUp.png"), forState: .Normal)
    button.addTarget(self, action: #selector(thumbsUpButtonPressed), forControlEvents: .TouchUpInside)

func thumbsUpButtonPressed() {
    print("thumbs up button pressed")
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download