iOS: 图像在 UIImageView 中显示不正确

iOS: Image is not displaying properly in UIImageView

我有一个 UIImageView,其中显示 UIImage 来自 JSON。问题是我想为 UIImageView 设置 cornerRadius。我为此输入了以下代码:

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

它显示 cornerRadiusUIImageView 的边框,但显示方式不正确。图像显示在角落外,如屏幕截图所示。

UIImageViewclipsToBounds 属性 设置为 YES

喜欢

设置imgVw.clipsToBounds=YES;

您需要像这样将 layermasksToBounds 属性 设置为 YES

self.imgVw.layer.masksToBounds = YES;