源码网商城,靠谱的源码在线交易网站 我的订单 购物车 帮助

源码网商城

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

  • 时间:2021-03-29 12:53 编辑: 来源: 阅读:
  • 扫一扫,手机访问
摘要:IOS获取系统相册中照片的示例代码
[b]先来看看效果图[/b] [img]http://files.jb51.net/file_images/article/201609/20169594311064.gif?20168594323[/img] [b]下面话不多少,我们直接上代码:[/b]
#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
[b]总结[/b] 以上就是IOS如何获取系统相册照片的示例代码,有需要的朋友们可以直接用,对大家的开发还是很有帮助的,如果大家有疑问可以留言交流。
  • 全部评论(0)
联系客服
客服电话:
400-000-3129
微信版

扫一扫进微信版
返回顶部