User User - 5 months ago 177x
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?


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")