先來看看效果圖
下面話不多少,我們直接上代碼:
#import "ViewController.h" @interface ViewController ()<UINavigationControllerDelegate,UIImagePickerControllerDelegate> @property (weak, nonatomic) IBOutlet UIImageView *IconView; @end @implementation ViewController - (IBAction)chooseImage { //彈出系統相冊 UIImagePickerController *pickVC = [[UIImagePickerController alloc] init]; //設置照片來源 pickVC.sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum; pickVC.delegate = self; [self presentViewController:pickVC animated:YES completion:nil]; } #pragma mark - UIImagePickerControllerDelegate -(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary<NSString *,id> *)info{ UIImage *photo = info[UIImagePickerControllerOriginalImage]; UIImageView *imageV = [[UIImageView alloc] init]; imageV.frame = self.IconView.frame; imageV.image = photo; imageV.userInteractionEnabled = YES; [self.view addSubview:imageV]; [self dismissViewControllerAnimated:YES completion:nil]; } @end
總結
以上就是IOS如何獲取系統相冊照片的示例代碼,有需要的朋友們可以直接用,對大家的開發還是很有幫助的,如果大家有疑問可以留言交流。