Search code examples
iosswiftuiimageviewxcode6

How to set imageView in circle like imageContacts in Swift correctly?


I want to show a picture into imageView like the image contact (in a circle) But when I try to show this, the imageView rescale his size and this doesn't show correctly in a circle.

 image.layer.borderWidth=1.0
 image.layer.masksToBounds = false
 image.layer.borderColor = UIColor.whiteColor().CGColor
 image.layer.cornerRadius = image.frame.size.height/2
 image.clipsToBounds = true

I want to show like this: enter image description here

But I get this: enter image description here

How can do the image resize to UIImageView size to show as a circle?

Thanks!


Solution

  • What frame size are you using for image? I can get a perfect circle if I set the frame to be a square.

    let image = UIImageView(frame: CGRectMake(0, 0, 100, 100))