How to capture UIView to UIImage without loss of quality on retina display

前端 未结 17 1766
时光取名叫无心
时光取名叫无心 2020-11-22 00:42

My code works fine for normal devices but creates blurry images on retina devices.

Does anybody know a solution for my issue?

+ (UIImage *) imageWith         


        
17条回答
  •  日久生厌
    2020-11-22 01:06

    Here's a Swift 4 UIView extension based on the answer from @Dima.

    extension UIView {
       func snapshotImage() -> UIImage? {
           UIGraphicsBeginImageContextWithOptions(bounds.size, isOpaque, 0)
           drawHierarchy(in: bounds, afterScreenUpdates: false)
           let image = UIGraphicsGetImageFromCurrentImageContext()
           UIGraphicsEndImageContext()
           return image
       }
    }
    

提交回复
热议问题