iOS selects a photo from a mobile album and displays Objective-c

Source: Internet
Author: User
Tags uikit

To set the app's permissions to access the album first:

Add Privacy-photo Library Usage description Permissions in the project's Info.plist file

ViewController.h:

1 #import<UIKit/UIKit.h>2 3 @interfaceViewcontroller:uiviewcontroller4 {5Iboutlet Uiimageview *myimageview;//associating with the ImageView view6 }7 8 9-(Ibaction) ButtonUp: (ID) sender;//Associate with a buttonTen  One @end

VIEWCONTROLLER.M:

1 #import "ViewController.h"2 3 4 @interfaceViewcontroller () <UINavigationControllerDelegate,UIImagePickerControllerDelegate>//Interface5 6 @end7 8 @implementationViewcontroller9 Ten- (void) Viewdidload { One [Super Viewdidload]; A     //additional setup after loading the view, typically from a nib. - } -  the  -- (void) didreceivememorywarning { - [Super didreceivememorywarning]; -     //Dispose of any resources the can be recreated. + } -  +  A-(Ibaction) ButtonUp: (ID) Sender { at     //Initialize the Uiimagepickercontroller class -Uiimagepickercontroller * Picker =[[Uiimagepickercontroller alloc] init]; -     //judging the data source as a photo album -Picker.sourcetype =Uiimagepickercontrollersourcetypesavedphotosalbum; -     //Set up proxy -Picker.Delegate=Self ; in     //Open Album - [self presentviewcontroller:picker animated:yes completion:nil]; to } +  - //Select Complete callback function the- (void) Imagepickercontroller: (Uiimagepickercontroller *) Picker Didfinishpickingmediawithinfo: (NSDictionary<NSString *,ID> *) info{ *     //Get Pictures $UIImage *image =Info[uiimagepickercontrolleroriginalimage];Panax Notoginseng [self dismissviewcontrolleranimated:yes completion:nil]; -  theMyimageview.image =image; + } A  the //User Cancel Selection +- (void) Imagepickercontrollerdidcancel: (Uiimagepickercontroller *) picker{ - [self dismissviewcontrolleranimated:yes completion:nil]; $ } $  -  - @end

iOS selects a photo from a mobile album and displays Objective-c

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: 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.