如何将一些图像作为一个图像保存到swift中的照片库?

问题描述 投票:0回答:1

enter image description here

第一个视图控制器中有三个imageView(两个甜甜圈png和一个Simpson图像)。是否有任何解决方案可以将这些图像作为一个图像捕获并保存到照片库中?谢谢。

swift uiimageview photolibrary
1个回答
1
投票

试试这个,传入包含你需要的所有子视图的基本视图:

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!
}
© www.soinside.com 2019 - 2024. All rights reserved.