iOS 通过View生成UIimage

729 阅读1分钟
 func imageWithView(targetView : UIView) -> UIImage?{
        UIGraphicsBeginImageContext(targetView.bounds.size);
        targetView.layer.render(in: UIGraphicsGetCurrentContext()!)
        let image = UIGraphicsGetImageFromCurrentImageContext();
        UIGraphicsEndImageContext();
        return image
    }