I select a photo from PhotoLibrary and How can I achieve below tasks
In this case, I am using Swift. I need to reconstruct the image in the next VC either thru :
loadImageButtonTapped
function, don't forget to assign the image picker delegate.Then, you should implement this method:
func imagePickerController (_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [UIImagePickerController.InfoKey : Any]){
// check if an image was selected,
// since a images are not the only media type that can be selected
if let img = info[.originalImage] {
methodToPassImageToViewController(img)
}
If you need to find out the size of the image, you cann access it's size
property.
To pass the image to another view controller, you could use one of these two options:
you could use this function for when you navigate from your view controller to another one using storyboard segues:
func prepareForSegue(_ segue: UIStoryboardSegue, sender sender: AnyObject?)
{
var destinationController = segue.destinationViewController
// now you can pass the image to the destination view controller
}
P.S: didFinishPickingImage
is deprecated since iOS 3, you should not use that method.