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:

  1. uiimagepickercontrollersourcetype.photolibrary
  2. uiimagepickercontrollersourcetype.camera
  3. 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

Popular posts from this blog

android - Gradle sync Error:Configuration with name 'default' not found -

java - Andrioid studio start fail: Fatal error initializing 'null' -

html - jQuery UI Sortable - Remove placeholder after item is dropped -