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