使背景透明具有圆角效果 - UIImage?

时间:2016-01-30 20:41:41

标签: ios swift uiimage

使用此功能可以对图像进行舍入,但是会留下白色背景,如何将背景变为透明?

func roundImage() -> UIImage
{
    let newImage = self.copy() as! UIImage
    let cornerRadius = self.size.height/2

    UIGraphicsBeginImageContextWithOptions(self.size, false , 0.0)
    let bounds = CGRect(origin: CGPointZero, size: self.size)
    UIBezierPath(roundedRect: bounds, cornerRadius: cornerRadius).addClip()
    newImage.drawInRect(bounds)
    let finalImage = UIGraphicsGetImageFromCurrentImageContext()
    UIGraphicsEndImageContext()
    return finalImage
}

0 个答案:

没有答案