商品详情页-生成海报分享,图片保存
// view生成图片的代码
extension UIView {
// 生成传入的frame大小的图片
public func xz_snapshot(ssFrame: CGRect) -> UIImage? {
// 最后一个参数:scale 如果是1的话 保存的图片很模糊 适合分享用的, scale 是3 就是3x的图片 适合保存到本地
UIGraphicsBeginImageContextWithOptions(bounds.size, false, 3)
if UIGraphicsGetCurrentContext() != nil {
drawHierarchy(in: ssFrame, afterScreenUpdates: true)
let screenshot = UIGraphicsGetImageFromCurrentImageContext()
UIGraphicsEndImageContext()
return screenshot
}
return nil
}
// 生成传入view的frame大小的图片
public var xz_snapshotImage: UIImage? {
// 最后一个参数:scale 如果是1的话 保存的图片很模糊 适合分享用的, scale 是3 就是3x的图片 适合保存到本地
UIGraphicsBeginImageContextWithOptions(bounds.size, false, 3)
if UIGraphicsGetCurrentContext() != nil {
drawHierarchy(in: bounds, afterScreenUpdates: true)
let screenshot &#