iOS development calls phone cameras and albums

Source: Internet
Author: User


How to click the button
-(void) Catchimage {Uialertcontroller *alert = [Uialertcontroller alertcontrollerwithtitle:@ "Select message:@ to select Photos" pref Erredstyle:uialertcontrollerstylealert]; Uialertaction *action1 = [uialertaction actionwithtitle:@ "Camera" Style:uialertactionstyledefault handler:^ ( Uialertaction * _nonnull action) {if ([Uiimagepickercontroller issourcetypeavailable:uiimagepickercontroll Ersourcetypecamera]) {Uiimagepickercontroller *picker = [[Uiimagepickercontroller alloc] init]; Picker.sourcetype = Uiimagepickercontrollersourcetypecamera; Picker.delegate = self; picker.allowsediting = YES; [Self presentviewcontroller:self animated:yes completion:nil]; } else {Uialertcontroller *controller = [Uialertcontroller alertcontrollerwithtitle:@ "No webcam" Messa Ge:nil Preferredstyle:uialertcontrollerstyleactionsheet]; Uialertaction *action = [Uialertaction actionwithtitle: @ "OK" style:uialertactionstyledestructive Handler:nil]; [Controller addaction:action]; [Self Presentviewcontroller:controller animated:yes completion:nil]; } }]; [Alert Addaction:action1]; Uialertaction *action2 = [uialertaction actionwithtitle:@ "album" Style:uialertactionstyledefault handler:^ ( Uialertaction * _nonnull action) {Uiimagepickercontroller *picker = [[Uiimagepickercontroller alloc] init] ; Picker.sourcetype = uiimagepickercontrollersourcetypephotolibrary; Picker.delegate = self; picker.allowsediting = YES; [Self Presentviewcontroller:picker animated:yes completion:nil]; }]; [Alert Addaction:action2]; [Self Presentviewcontroller:alert animated:yes completion:nil];} method to execute after selecting the picture-(void) Imagepickercontroller: (Uiimagepickercontroller *) Picker Didfinishpickingmediawithinfo: ( Nsdictionary<nsstring *,id> *) Info {UIImage *image = [info objectforkey:uiimagepickercontrolleroriginalimage]; Self.imageView.image = image; [Picker Dismissviewcontrolleranimated:yes completion:nil];} -(void) viewdidload {[Super viewdidload]; _button = [UIButton buttonwithtype:uibuttontyperoundedrect]; [_button settitle:@ "select Avatar" Forstate:uicontrolstatenormal]; _button.frame = CGRectMake (100, 100, 100, 30); [_button addtarget:self Action: @selector (Catchimage) forcontrolevents:uicontroleventtouchupinside]; [Self.view Addsubview:_button]; _imageview = [[Uiimageview alloc] Initwithframe:cgrectmake (100, 250, 150, 150)]; _imageview.backgroundcolor = [Uicolor Yellowcolor]; [Self.view Addsubview:_imageview]; Do any additional setup after loading the view.}

  

iOS development calls phone cameras and albums

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: info-contact@alibabacloud.com 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.