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?
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With