I have a code that takes a view and rounds it corners - turning it into a circle:
imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 8, 8)];
imageView.layer.cornerRadius = imageView.frame.size.width/2;
imageView.layer.masksToBounds = YES;
This works great on iOS 7 and iOS 8 - but doesn't work on iOS 9. How can I fix it?
You can give it round corners by changing the cornerRadius property of the view's layer . and smaller values give less rounded corners. Both clipsToBounds and masksToBounds are equivalent. It is just that the first is used with UIView and the second is used with CALayer .
Discussion. Setting the radius to a value greater than 0. 0 causes the layer to begin drawing rounded corners on its background. By default, the corner radius does not apply to the image in the layer's contents property; it applies only to the background color and border of the layer.
Turns out adding a background color to the ImageView fixes the issue...
Thanks to @YogevSitton answer I've searched over docs and found this:
It appears to be something in apple docs:
By default, the corner radius does not apply to the image in the layer’s contents property; it applies only to the background color and border of the layer.
So, to set cornerRadius to UIImageView it needs to have backgroundColor.
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