Circular ImageView iOS 8 / Xcode 6

I searched around and still cannot figure out what is right. I am trying to achieve a circular image in iOS 8. Prior to Xcode 6, I think the answer would be imageView.layer.cornerRadius . I tried this, but in Xcode 6 and iOS 8 I used Auto Layout now, which seems to me to be causing the problem, it seems to be working incorrectly. The form does not come out like a circle, but like some kind of eye shape or a deformed oval, its never a perfect circle. Is there any other way to achieve this with Autolayout?

+5
source share
4 answers

Check the height and width of the UIImageView. It should be the same. If it is not. Thereafter

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

or

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

Both lines work for you.

+3
source

I am using Xcode6 and checking with ios8.

Your image height and width should be the same.

The following code works fine for me.

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

Hope this works for you too.

+2
source

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

So the code is as follows

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

Also works fine ios 6 and above, including ios 8.

+1
source

Inject the following code to solve your problem.

 self.imageView.layer.cornerRadius = self.imageView.frame.size.width / 2; self.imageView.clipsToBounds = YES; 

If this is an AutoLayout problem. Remove the constraints, set the spacing and check the Aspect ratio .

0
source

Source: https://habr.com/ru/post/1208323/


All Articles