Setting Corner Radius on UIImageView not working

前端 未结 11 1873
心在旅途
心在旅途 2020-12-22 16:15

I\'m at a bit of a loss. I\'ve used the layer property of UIView to round the corners of multiple elements in my app. However, this one UIImageView is simply not complying.

相关标签:
11条回答
  • 2020-12-22 17:06

    You need to set the layer's masksToBounds property to YES:

    cell.previewImage.layer.masksToBounds = YES;

    This is because the UIImageView control creates a pseudo-subview to hold the UIImage object.

    0 讨论(0)
  • 2020-12-22 17:07

    Try this code:-

    self.imgaviewName.clipsToBounds = true
    self.imageviewName.layer.cornerRadius = 10
    
    0 讨论(0)
  • 2020-12-22 17:16

    I believe you need to set:

    cell.previewImage.layer.masksToBounds = YES;
    cell.previewImage.layer.opaque = NO;
    
    0 讨论(0)
  • 2020-12-22 17:16

    For imageView.contentMode = .scaleAspectFill the cornerRadius is not applied if the image is very large, depending on the hardware.

    Some tests with resized panorama images:

    • iPhone X, image size 5000x1107:
    0 讨论(0)
  • 2020-12-22 17:17

    Try this below piece of code

    cell.previewImage.layer.cornerRadius = 20;
    cell.previewImage.clipsToBounds = YES;
    
    0 讨论(0)
提交回复
热议问题