先测试下

51 阅读1分钟

extension UIView {

    func screenshot() -> UIImage? {

        UIGraphicsBeginImageContextWithOptions(self.bounds.size, true, 0);

        self.drawHierarchy(in: self.bounds, afterScreenUpdates: false);

        let snapshotImage = UIGraphicsGetImageFromCurrentImageContext();

        UIGraphicsEndImageContext();

        return snapshotImage;

    }

}