Small instance of iOS development--uiimagepickercontroller

Source: Internet
Author: User

Preface: This post is I read foreign iOS programming tutorial an introductory article of the learning process summary, difficult, because is the introduction. Basically is the introduction Uiimagepickercontroller this controller, then this controller is why? is to invoke the device camera function. You may need to test on a real machine in the back, because the iphone simulator can't support the camera function, and running tests will crash.

Website: Http://

In fact, I follow this blog to explain the process, I did it again, and also knocked over the code, and soon became familiar with the Uiimagepickercontroller is what the thing.

1, the first simple to create a project, and then in the storyboard and corresponding. m file to add the relevant code, this concise tutorial does not use automatic layout, not to say, look at the picture literacy:

2, the following is the complete implementation of this VIEWCONTROLLER.M:

1 #import "ViewController.h"2 3 @interfaceViewcontroller () <UIImagePickerControllerDelegate,UINavigationControllerDelegate>4 5@property (Strong, nonatomic) iboutlet Uiimageview *ImageView;6 7 @end8 9 @implementationViewcontrollerTen  One- (void) Viewdidload { A [Super Viewdidload]; -      -     //This code will automatically determine whether the current device has a camera function, if not, will pop-up window prompt the     if(![Uiimagepickercontroller Issourcetypeavailable:uiimagepickercontrollersourcetypecamera]) { -          -Uialertview *myalertview = [[Uialertview alloc] Initwithtitle:@"Error" -Message@"Device has no camera" +                                                              Delegate: Nil -Cancelbuttontitle:@"OK" + Otherbuttontitles:nil]; A          at [Myalertview show]; -          -     } - } --(Ibaction) Takephotot: (UIButton *) Sender { -     //To Create a Uiimagepickercontroller controller object inUiimagepickercontroller *picker =[[Uiimagepickercontroller alloc] init]; -Picker.Delegate=Self ; toPicker.allowsediting =YES; +Picker.sourcetype =Uiimagepickercontrollersourcetypecamera; -      the [self presentviewcontroller:picker animated:yes completion:nil]; * } $-(Ibaction) Selectphoto: (UIButton *) Sender {Panax Notoginseng     //To Create a Uiimagepickercontroller controller object -Uiimagepickercontroller *picker =[[Uiimagepickercontroller alloc] init]; thePicker.Delegate=Self ; +Picker.allowsediting =YES; APicker.sourcetype =uiimagepickercontrollersourcetypephotolibrary; the      + [self presentviewcontroller:picker animated:yes completion:nil]; - } $ #pragmaMark-Proxy method $-(void) Imagepickercontroller: (Uiimagepickercontroller *) Picker Didfinishpickingmediawithinfo: (NSDictionary<NSString *,ID> *) info{ -uiimage* Chosenimage =Info[uiimagepickercontrollereditedimage]; -Self.imageView.image =Chosenimage; the      - [Picker Dismissviewcontrolleranimated:yes completion:nil];Wuyi } the-(void) Imagepickercontrollerdidcancel: (Uiimagepickercontroller *) picker{ - [Picker Dismissviewcontrolleranimated:yes completion:nil]; Wu } -  About @end

Just this part of the code, nothing else.
Finally, use your real machine test.

Small instance of iOS development--uiimagepickercontroller

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.