[英]Apply circular crop to UIImage or UIImageView
How can I programmatically apply a circular crop out to a UIImage
or a UIImageView
?如何以编程方式将圆形裁剪应用到
UIImage
或UIImageView
? Is it possible, or must I use a graphical mask?是否可能,或者我必须使用图形蒙版?
Till now I am using a graphical mask (a png image) but the final crop out result is ovalized, rather than a perfect circle.到目前为止,我使用的是图形蒙版(png 图像),但最终的裁剪结果是椭圆形的,而不是完美的圆形。
[imageView setContentMode: UIViewContentModeScaleAspectFit];
[imageView setContentMode: UIViewContentModeScaleAspectFill];
also do not solve the problem.也解决不了问题。
Please note that the UIImageView
that the image is applied to is already defined exactly as a square in IB.请注意,应用图像的
UIImageView
已经在 IB 中精确定义为正方形。
If the UIImageView
is already a square then you can set the corner radius of its layer to half of its width/height如果
UIImageView
已经是一个正方形,那么您可以将其图层的角半径设置为其宽度/高度的一半
[imageView.layer setCornerRadius:imageView.frame.size.width / 2.0];
[imageView.layer setMasksToBounds:YES];
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.