ios - 如何将图像存储到 swift ios 中的应用程序?

标签 ios swift uiimageview

    @IBAction func btnClicked(){

    let alertController = UIAlertController(title: "Choose an option", message: "", preferredStyle: .Alert)

    let cameraRollAction = UIAlertAction(title: "Camera Roll", style: .Default) { (action) in
        self.imagePicker.delegate = self
        self.imagePicker.sourceType = UIImagePickerControllerSourceType.SavedPhotosAlbum;
        self.imagePicker.allowsEditing = true
        self.presentViewController(self.imagePicker, animated: true, completion: nil)


    }
    alertController.addAction(cameraRollAction)

    let takePictureAction = UIAlertAction(title: "Take a picture", style: .Default) { (action) in
        self.imagePicker.delegate = self
        self.imagePicker.allowsEditing = true
        self.imagePicker.sourceType = UIImagePickerControllerSourceType.Camera
        self.imagePicker.cameraCaptureMode = .Photo
        self.imagePicker.modalPresentationStyle = .FullScreen
        self.presentViewController(self.imagePicker,
            animated: true,
            completion: nil)
    }
    alertController.addAction(takePictureAction)



}

如何将图像存储到我从设备中选择的应用程序中?每当我选择图片时,它都会出现,但当我关闭并重新打开应用程序时,图片就会消失。

最佳答案

另一种方法是,您可以将图像保存在应用程序的文档目录中。这些图像的所有路径都可以存储在 NSUserDefaults 中。

检查此链接以将图像保存到文档目录:

Click me !

相应地添加您的 NSUserDefaults 逻辑。

谢谢。

关于ios - 如何将图像存储到 swift ios 中的应用程序?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34917288/

相关文章:

ios - 如何更改 Storyboard的大小?

ios - 检测IOS中uiimageview中的透明像素

iphone - 没有 GameKit 的 iOS 蓝牙

iphone - iOS 中的词定义

ios - 准备 segue 导致 "found nil while unwrapping an Optional value"

swift - NSTextView 拖动带有自定义属性的文本

ios - 在像 Twitter 这样的 UIImageView 中缩放图像

ios - 类型 'UIImageView' 的值在 swift 4 中没有成员 'kf'

ios - Facebook 开发者登录错误

ios - 以编程方式自动布局功能