Hi i am working on a universal application (iPhone/iPad). one feature is that i have to select a photo from album and show it on UIImageView.
Now problem is that it
Here i show you the SWIFT way:
import UIKit
class StoreItemViewController: UIViewController, UIImagePickerControllerDelegate, UINavigationControllerDelegate
{
@IBOutlet weak var button: UIButton!
@IBOutlet weak var productImage: UIImageView!
var popOver:UIPopoverController?
@IBAction func buttonSelected(sender:UIButton)
{
if UIImagePickerController.isSourceTypeAvailable(UIImagePickerControllerSourceType.SavedPhotosAlbum)
{
var imagePickerController = UIImagePickerController()
imagePickerController.delegate = self
imagePickerController.sourceType = UIImagePickerControllerSourceType.SavedPhotosAlbum
imagePickerController.allowsEditing = false
if UIDevice.currentDevice().userInterfaceIdiom == UIUserInterfaceIdiom.Pad
{
self.popOver = UIPopoverController(contentViewController: imagePickerController)
self.popOver?.presentPopoverFromRect(self.productImage.bounds, inView: self.productImage, permittedArrowDirections: UIPopoverArrowDirection.Any, animated: true)
}
else
{
self.presentViewController(imagePickerController, animated: true, completion: { imageP in
})
}
}
}
func imagePickerController(picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [NSObject : AnyObject]) {
//do anything with the image
let selectedImage = info[UIImagePickerControllerOriginalImage] as UIImage
//closing the popup
popOver?.dismissPopoverAnimated(true)
}
func imagePickerControllerDidCancel(picker: UIImagePickerController)
{
println("cancel")
//closing the popup
popOver?.dismissPopoverAnimated(true)
}
}