How to set corner radius of imageView?

后端 未结 10 661
清酒与你
清酒与你 2020-12-13 01:50

In Objective-C such line

self.mainImageView.layer.cornerRadius = CGRectGetWidth(self.mainImageView.frame)/4.0f;

does its job, I tried it in

10条回答
  •  伪装坚强ぢ
    2020-12-13 02:30

    Layer draws out of clip region, you need to set it to mask to bounds:

    self.mainImageView.layer.masksToBounds = true
    

    From the 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. However, setting the masksToBounds property to true causes the content to be clipped to the rounded corners

提交回复
热议问题