先來看看效果圖
下面話不多少,我們直接上代碼:
#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如何擷取系統相簿照片的範例程式碼,有需要的朋友們可以直接用,對大家的開發還是很有協助的,如果大家有疑問可以留言交流。