视图生成图片
func generatePicture(layer: CALayer,size: CGSize) -> UIImage {
let format = UIGraphicsImageRendererFormat()
format.prefersExtendedRange = true
let rect = CGRect(origin: .zero, size: size)
let renderer = UIGraphicsImageRenderer(bounds: rect, format: format)
let image = renderer.image { (context) in
context.cgContext.concatenate(CGAffineTransform.identity.scaledBy(x: 1, y: 1))
return layer.render(in: context.cgContext)
}
return image
}
网友评论