Abhi Abhi - 4 months ago 8
Objective-C Question

iOS: Image is not displaying properly in UIImageView

I have a

UIImageView
in which a
UIImage
is showing which comes from JSON. The problem is that I want to set the
cornerRadius
for the
UIImageView
. I put the following code for it:

imgVw.layer.cornerRadius = 30.0;
imgVw.layer.borderWidth = 2.0;
imgVw.layer.borderColor = [UIColor blackColor].CGColor;


It displays the
cornerRadius
and border for
UIImageView
but not in the proper way. The image is showing outside the corners like in screenshot.

enter image description here

Answer

You need to set the masksToBounds property of layer to YES like this

self.imgVw.layer.masksToBounds = YES;