Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Create UIImageView with circle border iOS

I am trying to create a border around my UIIMageView which is a perfect circle using cornerRadius. Everything i've looked at says my code is correct, but it returns more of a diamond shape. (i've imported quartzCore, not sure I needed to)

image.layer.cornerRadius = (image.bounds.size.width/2);
image.layer.borderWidth = 5;
image.layer.borderColor = [UIColor whiteColor].CGColor;

Any ideas?

like image 761
work_gg Avatar asked Apr 20 '26 03:04

work_gg


2 Answers

image.layer.cornerRadius = image.frame.size.width /2;
image.layer.masksToBounds = YES;
image.layer.borderWidth = 5;
image.layer.borderColor = [UIColor whiteColor].CGColor;

The height and width of your imageview must be equal

like image 198
Subbu Avatar answered Apr 22 '26 18:04

Subbu


Have you tried to add:

image.layer.masksToBounds = YES;

Another thing: is the width of your image equal to its height?

like image 34
eschanet Avatar answered Apr 22 '26 19:04

eschanet



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!