我想将a UIImage切成一个圆圈,以便可以将其用作注释。我在此网站上找到的每个答案都描述了创建一个UIImageView,然后对其进行修改并显示出来,但是您无法将注释的图像设置为UIImageView,只能是UIImage。我应该怎么做?
UIImage
UIImageView
如果需要,请确保导入QuarzCore。
func maskRoundedImage(image: UIImage, radius: CGFloat) -> UIImage { let imageView: UIImageView = UIImageView(image: image) let layer = imageView.layer layer.masksToBounds = true layer.cornerRadius = radius UIGraphicsBeginImageContext(imageView.bounds.size) layer.render(in: UIGraphicsGetCurrentContext()!) let roundedImage = UIGraphicsGetImageFromCurrentImageContext() UIGraphicsEndImageContext() return roundedImage! }