Capture UIView and Save as Image

前端 未结 7 519
孤城傲影
孤城傲影 2020-12-02 19:31

First of i Add the UILable on UIImageView and then after i screenshot the UIView, the image not proper capture the UIView

7条回答
  •  萌比男神i
    2020-12-02 19:41

    Swift 3 Version:

    func takeSnapshotOfView(view:UIView) -> UIImage? {
        UIGraphicsBeginImageContext(CGSize(width: view.frame.size.width, height: view.frame.size.height))
        view.drawHierarchy(in: CGRect(x: 0.0, y: 0.0, width: view.frame.size.width, height: view.frame.size.height), afterScreenUpdates: true)
        let image = UIGraphicsGetImageFromCurrentImageContext()
        UIGraphicsEndImageContext()
        return image
    }
    

提交回复
热议问题