@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 中。
检查此链接以将图像保存到文档目录:
相应地添加您的 NSUserDefaults 逻辑。
谢谢。
关于ios - 如何将图像存储到 swift ios 中的应用程序?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34917288/