IOS获取系统相册中照片的示例代码

时间:2022-09-19 20:39:06

先来看看效果图

IOS获取系统相册中照片的示例代码

下面话不多少,我们直接上代码:

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#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如何获取系统相册照片的示例代码,有需要的朋友们可以直接用,对大家的开发还是很有帮助的,如果大家有疑问可以留言交流。