How do I turn a rectangular image view into a circular image view that can hold shape in auto layout without setting width and height restraints? Thereby allowing the imageV
Add a 1:1 aspect ratio constraint to the imageView
for it to remain circular, despite any height or width changes.
If you have subclassed the UIImageView. Then just add this piece of magical code in it.
Written in : Swift 3
override func layoutSubviews() {
super.layoutSubviews()
if self.isCircular! {
self.layer.cornerRadius = self.bounds.size.width * 0.50
}
}
create new interface in your .h file like
@interface CornerClip : UIImageView
@end
and implementation in .m file like
@implementation cornerClip
-(void)layoutSubviews
{
[super layoutSubviews];
CGFloat radius = self.bounds.size.width / 2.0;
self.layer.cornerRadius = radius;
}
@end
now just give class as "CornerClip" to your imageview. 100% working... Enjoy