打开本地相册并添加到视图
- (void)viewDidLoad {
[super viewDidLoad];
self.title = @"上传壁纸";
// 点击UIButton AddWallpaper 就是打开相册添加图片
[_AddWallpaper addTarget:self action:@selector(AddWallpaperClick) forControlEvents:UIControlEventTouchUpInside];
// 点击UIButton UpWallPaper 就是上传图片
[_UpWallpaper addTarget:self action:@selector(UpWallpaperClick) forControlEvents:UIControlEventTouchUpInside];
}
- (void)AddWallpaperClick {
UIAlertController *alertController = [UIAlertController alertControllerWithTitle:nil message:@"请选择图片" preferredStyle:UIAlertControllerStyleActionSheet];
UIAlertAction *OKAction = [UIAlertAction actionWithTitle:@"打开相册" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
// 打开相册
[self open];
}];
UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:nil];
[alertController addAction:OKAction];
[alertController addAction:cancelAction];
[self presentViewController:alertController animated:YES completion:nil];
}