I am writing my first iOS application (iPhone only) with Swift. The main application view should allow user to choose the image from the photo gallery.
I\'ve found
You can do like here
var avatarImageView = UIImageView()
var imagePicker = UIImagePickerController()
func takePhotoFromGallery() {
imagePicker.delegate = self
imagePicker.sourceType = .savedPhotosAlbum
imagePicker.allowsEditing = true
present(imagePicker, animated: true)
}
func imagePickerController(_ picker: UIImagePickerController,
didFinishPickingMediaWithInfo info: [UIImagePickerController.InfoKey : Any]) {
if let pickedImage = info[.originalImage] as? UIImage {
avatarImageView.contentMode = .scaleAspectFill
avatarImageView.image = pickedImage
}
self.dismiss(animated: true)
}
Hope this was helpful