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?
Asked
Active
Viewed 7,401 times
5

dandan78
- 13,328
- 13
- 64
- 78

user3796045
- 63
- 1
- 6
-
2The cornerRadius should be half the width/height to be a circle. – Krys Jurgowski Dec 04 '14 at 06:06
-
Apply constraints on size, i.e width and height of the imageView, and set the cornerRadius= width/2. The imageView will be a circle if width=height. – zaheer Dec 04 '14 at 06:08
-
http://stackoverflow.com/a/27222863/3767017(by layer property u can also change the geometry) and http://stackoverflow.com/a/25616952/3767017 and be cautious about your frame of imageView. – Anurag Bhakuni Dec 04 '14 at 06:50
-
1@user3796045:Please accept the answer of upvote for it if they were useful to you. – Manthan Dec 22 '14 at 07:51
-
What have you tryied? http://mattgemmell.com/what-have-you-tried/ Looks to me like you just didn't set a height constraint. – Alex Cio May 15 '15 at 10:27
4 Answers
3
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.

Indrajeet
- 5,490
- 2
- 28
- 43
2
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.

Manthan
- 3,856
- 1
- 27
- 58
1
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.

dandan78
- 13,328
- 13
- 64
- 78

Sudhin Davis
- 2,010
- 13
- 18
0
Implement the following code it will solve your problem.
self.imageView.layer.cornerRadius = self.imageView.frame.size.width / 2;
self.imageView.clipsToBounds = YES;
If it is the problem by AutoLayout
. Clear the constraints, put on the spacing and tick on Aspect ratio
.

Nischal Hada
- 3,230
- 3
- 27
- 57

Hem Poudyal
- 321
- 6
- 16