I am trying to load a circular imageview in my ios app. I have tried all the combinations that has been listed in stack-overflow, but i still get the same error. I tried every mentioned step over here How to set imageView in circle like imageContacts in Swift correctly?
What I have done is this
- I have created an image view in my storyboard - with height=300, width=300, view mode = aspect fit.
- I defined constraint to place the image view at the horizontal and vertical center. Also defined trailing from top and right edge
The 4 constraint are as follows
i. ImageView.centerY = centreY
ii.ImageView.centerY = centreY
iii. ImageView.top = TopLayoutGUide.bottom + 103
iv. trailingMargin = ImageView.trailing + 125
In my controller file I have `declared and IBOutlet for imageview as
@IBOutlet var imageView: UIImageView!
In my controller file I have used the following piece of code to make it circular
func circularImage(photoImageView: UIImageView?) { photoImageView!.layer.frame = CGRectInset(photoImageView!.layer.frame, 0, 0) photoImageView!.layer.borderColor = UIColor.grayColor().CGColor photoImageView!.layer.cornerRadius = photoImageView!.frame.width/2 photoImageView!.layer.masksToBounds = false photoImageView!.clipsToBounds = true photoImageView!.layer.borderWidth = 0.5 photoImageView!.contentMode = UIViewContentMode.ScaleAspectFill }
I am however, getting an oval shaped image view.