How to make an ellipse/circular UIImage with transparent background?
问题 This is the code I am using extension UIImage { var ellipseMasked: UIImage? { guard let cgImage = cgImage else { return nil } let rect = CGRect(origin: .zero, size: size) return UIGraphicsImageRenderer(size: size, format: imageRendererFormat) .image{ _ in UIBezierPath(ovalIn: rect).addClip() UIImage(cgImage: cgImage, scale: scale, orientation: imageOrientation) .draw(in: rect) } } } This is the image I got The background color is black. How can I make the background transparent? I tried