How to save a couple of images as one image to pho

2019-09-03 17:04发布

enter image description here

There are three imageViews in first view controller (two donuts png and one Simpson image). Are there any solutions that I can capture these images as one image and save it to photo library? Thanks.

1条回答
我欲成王,谁敢阻挡
2楼-- · 2019-09-03 17:33

Try this, passing in the base view that has all the subviews you need:

func createImage(from aView:UIView) -> UIImage {
    UIGraphicsBeginImageContextWithOptions(CGSize(width: aView.frame.width, height: aView.frame.height), true, 0)
    aView.layer.render(in: UIGraphicsGetCurrentContext()!)
    let image = UIGraphicsGetImageFromCurrentImageContext()
    UIGraphicsEndImageContext()
    return image!
}
查看更多
登录 后发表回答