屏幕截图
2018-04-24 本文已影响7人
child_cool
override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
imageView.image = UIImage(named: "1.jpg")
imageView.image = UIApplication.shared.delegate?.window??.yj_capture()
}
}
extension UIView {
/// 屏幕截图
func yj_capture() -> UIImage? {
UIGraphicsBeginImageContextWithOptions(self.bounds.size, self.isOpaque, UIScreen.main.scale)
if self.responds(to: #selector(drawHierarchy(in:afterScreenUpdates:))) {
self.drawHierarchy(in: self.bounds, afterScreenUpdates: true)
} else {
self.layer.render(in: UIGraphicsGetCurrentContext()!)
}
let image = UIGraphicsGetImageFromCurrentImageContext()
UIGraphicsEndImageContext()
return image
}
}