uikit - How to add an image picker to the main storyboard xcode swift? -
i want add feature of choosing image images in iphone on iphone application in swift, wanted know given features , how can them. need basic features allow me browse albums , choose in image loaded in uiimageview.
implementing retrieve image gallery in swift work make view controller class should have implement delegate methods of uiimagepickercontrollerdelegate. make top of class this:
class viewcontroller: uiviewcontroller, uiimagepickercontrollerdelegate, uinavigationcontrollerdelegate { @iboutlet var imageview: uiimageview! let imagepicker = uiimagepickercontroller() override func viewdidload() { super.viewdidload() imagepicker.delegate = self }
buttontapped action made earlier, , we’ll call uiimagepickercontroller there:
@ibaction func loadimagebuttontapped(sender: uibutton) { imagepicker.allowsediting = false imagepicker.sourcetype = .photolibrary presentviewcontroller(imagepicker, animated: true, completion: nil) }
uiimagepickercontrollersourcetype, gives 3 options:
- uiimagepickercontrollersourcetype.photolibrary
- uiimagepickercontrollersourcetype.camera
uiimagepickercontrollersourcetype.savedphotosalbum
func imagepickercontroller(picker: uiimagepickercontroller, didfinishpickingmediawithinfo info: [nsobject : anyobject]) { if let pickedimage = info[uiimagepickercontrolleroriginalimage] as? uiimage { imageview.contentmode = .scaleaspectfit imageview.image = pickedimage } dismissviewcontrolleranimated(true, completion: nil) }
Comments
Post a Comment