IOS獲取系統(tǒng)相冊中照片的示例代碼
更新時間:2016年09月05日 09:44:55 投稿:daisy
在大家的日常開發(fā)中,經(jīng)常會遇到有的app需要從系統(tǒng)相冊中獲取圖片,如設(shè)置用戶頭像等,下面這篇文章給大家分享這個功能的實現(xiàn),有需要的可以參考借鑒。
先來看看效果圖
下面話不多少,我們直接上代碼:
#import "ViewController.h" @interface ViewController ()<UINavigationControllerDelegate,UIImagePickerControllerDelegate> @property (weak, nonatomic) IBOutlet UIImageView *IconView; @end @implementation ViewController - (IBAction)chooseImage { //彈出系統(tǒng)相冊 UIImagePickerController *pickVC = [[UIImagePickerController alloc] init]; //設(shè)置照片來源 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
總結(jié)
以上就是IOS如何獲取系統(tǒng)相冊照片的示例代碼,有需要的朋友們可以直接用,對大家的開發(fā)還是很有幫助的,如果大家有疑問可以留言交流。
相關(guān)文章
iOS - UIButton(UIEdgeInsets)/設(shè)置button上的文字和圖片上下垂直居中對齊
這篇文章主要介紹了iOS - UIButton(UIEdgeInsets)/設(shè)置button上的文字和圖片上下垂直居中對齊的相關(guān)資料,需要的朋友可以參考下2015-09-09iOS DispatchSourceTimer 定時器的具體使用
定時器在很多地方都可以用到,本文主要介紹了iOS DispatchSourceTimer 定時器的具體使用,文中通過示例代碼介紹的非常詳細(xì),具有一定的參考價值,感興趣的小伙伴們可以參考一下2022-05-05