How do I get an image from the iOS photo library and display it in UIWebView
[Updated to swift 4]
You can use UIImagePickerController
delegate to select the image (or url) you want to edit.
you can do this like this:
let pickerController = UIImagePickerController()
pickerController.sourceType = .photoLibrary
pickerController.delegate = self
self.navigationController?.present(pickerController, animated: true, completion: {
})
in the delegate implementation you can use the path of the image or the image itself:
// This method is called when an image has been chosen from the library or taken from the camera.
func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : Any]) {
//You can retrieve the actual UIImage
let image = info[UIImagePickerControllerOriginalImage] as? UIImage
//Or you can get the image url from AssetsLibrary
let path = info[UIImagePickerControllerReferenceURL] as? URL
picker.dismiss(animated: true, completion: nil)
}
Swift 4
class ViewController: UIViewController {
var pickedImage:UIImage?
@IBAction func ActionChooseImage(sender:UIButton){
let imagePickerController = UIImagePickerController()
imagePickerController.sourceType = .photoLibrary
imagePickerController.delegate = self
self.present(imagePickerController, animated: true, completion: nil)
}
}
extension ViewController: UIImagePickerControllerDelegate,UINavigationControllerDelegate {
func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : Any]) {
let image = info[UIImagePickerControllerOriginalImage] as? UIImage
self.pickedImage = image
picker.dismiss(animated: true, completion: nil)
}
}
Ref