在大家的日常开发中,经常会遇到有的app需要从系统相册中获取图片,如设置用户头像等,下面这篇文章给大家分享这个功能的实现,有需要的可以参考借鉴。
先来看看效果图

下面话不多少,我们直接上代码:
#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如何获取系统相册照片的示例代码,有需要的朋友们可以直接用,对大家的开发还是很有帮助的,如果大家有疑问可以留言交流。
织梦狗教程
本文标题为:IOS获取系统相册中照片的示例代码
基础教程推荐
猜你喜欢
- IOS 播放系统提示音使用总结(AudioToolbox) 2023-03-01
- 解决Android Studio突然不显示logcat日志的问题 2023-02-04
- IOS应用内跳转系统设置相关界面的方法 2022-11-20
- Android中的webview监听每次URL变化实例 2023-01-23
- Flutter绘图组件之CustomPaint使用详解 2023-05-12
- Android多返回栈技术 2023-04-15
- Flutter手势密码的实现示例(附demo) 2023-04-11
- android studio按钮监听的5种方法实例详解 2023-01-12
- Android开发使用RecyclerView添加点击事件实例详解 2023-06-15
- iOS开发教程之XLForm的基本使用方法 2023-05-01
