如何从相册中保存选定的图像以快速显示任何视图控制器

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

我正在使用我的应用程序,但我一度陷入困境。有一个UIIMAGEVIEW和一个UPLOAD按钮。因此,当用户单击“上传”按钮时,他会在选择图像后进入照片库以选择图像,我正在UIIMAGEVIEW上显示该图像。所以我的问题是:在UIIMAGEVIEW上显示图像后,我想将该图像保存在应用程序中以在不同的View Controller上显示同一图像。

swift xcode uibutton uiimageview
1个回答
0
投票

您可以将图像放在全局变量中。全局变量可以在所有应用程序中使用。 :

var imageSelected:UIImage? // Value will be nil if no image has been set

class ViewController1 {
    // Puts your image inside a global variable
    image = yourImage
}

class ViewController2 {
    // Uses the image that was defined inside the global variable
    @IBOutlet weak var imageView: UIView!
    imageView.image = imageSelected
}
© www.soinside.com 2019 - 2024. All rights reserved.