欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  移动技术

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

程序员文章站 2023-12-14 13:02:40
先来看看效果图 下面话不多少,我们直接上代码: #import "viewcontroller.h" @interface viewcontrolle...

先来看看效果图

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

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

#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如何获取系统相册照片的示例代码,有需要的朋友们可以直接用,对大家的开发还是很有帮助的,如果大家有疑问可以留言交流。

上一篇:

下一篇: