问题
I am trying to convert my custom UIView
into UIImage
using core graphic, but sometimes it turns to black, my whole UIImage
looks like a black image.
What I noticed is that if the height of my UIView
is exceeding 4096 regardless what the width is then the produced UIImage
will be black!
Note 1: my custom UIView
is loaded from a nib file.
Here is my code:
func getImageWithScale(_ scale: CGFloat) -> UIImage {
let size = self.bounds.size.applying(CGAffineTransform(scaleX: scale, y: scale))
UIGraphicsBeginImageContextWithOptions(size, true, 1)
self.drawHierarchy(in: CGRect(origin: CGPoint.zero, size: size), afterScreenUpdates: true)
let image = UIGraphicsGetImageFromCurrentImageContext()
UIGraphicsEndImageContext()
return image!
}
来源:https://stackoverflow.com/questions/42904135/uiview-drawhierarchy-creating-a-black-image