Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make UIButton a circle?

I have been trying to make the UIButton in the cells a perfect circle. Unfortunately the circle has been formed based on the background image rather than the UIButton frame.

The code I have for creating a circle:

cell.StoryViewButton.setImage(image, forState: .Normal)
cell.StoryViewButton.frame = CGRectMake(50, 8, 100, 100)
cell.StoryViewButton.layer.masksToBounds = false
cell.StoryViewButton.layer.cornerRadius = cell.StoryViewButton.frame.width/2
cell.StoryViewButton.clipsToBounds = true

The output looks like this: Output Images for each cell

What can I do to get the perfect circle button frames that I want?

like image 465
Kolby O'Malley Avatar asked Jun 12 '16 03:06

Kolby O'Malley


1 Answers

Try something like this

 cell.StoryViewButton.layer.masksToBounds = true
 cell.StoryViewButton.layer.cornerRadius = cell.StoryViewButton.frame.width/2

If you need to create a circle of view you have to set masksToBounds to true, do not set clipsToBounds

Hope this will help you.

like image 127
Nirav D Avatar answered Oct 09 '22 08:10

Nirav D