swift--视图生成图片

2021-04-08  本文已影响0人  龙之天下

视图生成图片

 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
}
上一篇下一篇

猜你喜欢

热点阅读