Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Circular ImageView iOS 8 / Xcode 6

I've searched around and still can't seem to get this right. I'm trying to achieve a circular image in iOS 8. Before Xcode 6, I think the answer would've been imageView.layer.cornerRadius property. I've tried this but in Xcode 6 and iOS 8 now using Auto Layout, which I think is causing the issue, it doesn't seem to work correctly. The shape doesn't come out as a circle but as some eye looking shape or a deformed oval, its never a perfect circle. Is there any other way of achieving this still with Autolayout?

like image 385
user3796045 Avatar asked Dec 04 '14 05:12

user3796045


3 Answers

Check your height and width of UIImageView. It should be same. If not them make it. After that

imageView.layer.cornerRadius = imageView.frame.size.width/2;

or

imageView.layer.cornerRadius = imageView.frame.size.height/2;

Both lines work for you.

like image 173
Indrajeet Avatar answered Sep 29 '22 21:09

Indrajeet


I am using Xcode6 and and checking with ios8.

Your Imageview's height and width should be same.

The below code works fine for me.

yourImageView.layer.cornerRadius = img.frame.size.height /2;
yourImageView.layer.masksToBounds = YES;
yourImageView.layer.borderWidth = 0.1;

Hope it works for you too.

like image 33
Manthan Avatar answered Sep 29 '22 22:09

Manthan


Try this code, corner radius should be half of the width or height of the provided photo view and it must be square in shape.

So the code go like this

[self.photoView.layer setCornerRadius:CGRectGetHeight(self.photoView.frame)/2];
[self.photoView.layer setMasksToBounds:YES];

Also works fine ios 6 and above including ios 8.

like image 32
Sudhin Davis Avatar answered Sep 29 '22 22:09

Sudhin Davis