Setting Corner Radius on UIImageView not working

前端 未结 11 1934
心在旅途
心在旅途 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 16:57

    Also worth noting that

    1. If you are using aspectFit AND cornerRadius with clipsToBounds/masksToBounds, you won't get the rounded corners.

    i.e if you have this

    theImageView.contentMode = .scaleAspectFit
    

    and

       theImageView.layer.cornerRadius = (theImageView.frame.size.height)/2
        theImageView.clipsToBounds = true
    

    or

    theImageView.layer.masksToBounds = true
    

    It won't work. you will have to get rid of aspectFit code

    //theImageView.contentMode = .scaleAspectFit
    
    1. Make sure the width and the height for the Image View is same

提交回复
热议问题