• 调用相册


     1 #import "ViewController.h"
     2 
     3 @interface ViewController ()<UIImagePickerControllerDelegate>
     4 
     5 @end
     6 
     7 @implementation ViewController
     8 
     9 - (void)viewDidLoad {
    10     [super viewDidLoad];
    11     
    12     UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
    13     btn.backgroundColor = [UIColor grayColor];
    14     btn.frame = CGRectMake(20, 30, 80, 80);
    15     [btn addTarget:self action:@selector(showImagerPicker) forControlEvents:UIControlEventTouchUpInside];
    16     [self.view addSubview:btn];
    17     
    18 }
    19 
    20 -(void)showImagerPicker{
    21     UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];//创建对象
    22     imagePicker.sourceType = 0;//设置类型(相册、相机)
    23     
    24     imagePicker.allowsEditing = YES;//是否允许编辑,默认no,设置为yes时,点击图片会进入编辑界面(裁剪)
    25     imagePicker.delegate = self;
    26     [self presentViewController:imagePicker animated:YES completion:nil];//弹出相册/相机
    27 }
    28 
    29 //选择图片后调用的代理方法
    30 -(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info{
    31     
    32     NSLog(@"----%@",info);
    33     
    34     UIImage *image = info[@"UIImagePickerControllerEditedImage"];//获取图片
    35     UIImageView *imageView = [[UIImageView alloc] initWithImage:image];
    36     imageView.frame = CGRectMake(30, 140, 90, 90);
    37     [self.view addSubview:imageView];
    38     
    39     [self dismissViewControllerAnimated:YES completion:nil];//消失imagepicker
    40     
    41 }
    42 
    43 - (void)didReceiveMemoryWarning {
    44     [super didReceiveMemoryWarning];
    45     // Dispose of any resources that can be recreated.
    46 }
    47 
    48 @end
  • 相关阅读:
    Oracle数据库的左连接和右连接(+)
    Web文件上传模块 Plupload
    增加反向链接的35个技巧
    google map api 与jquery结合使用(1)控件,监听器[转帖]
    教你在windows 7/xp 下安装使用mencoder
    Oracle 全文索引
    提高关键词排名的28个SEO技巧
    二叉树遍历及C语言实现
    小额担保业务管理系统详细设计介绍
    C#与数据结构二叉树的遍历
  • 原文地址:https://www.cnblogs.com/hanweifeng/p/5190497.html
Copyright © 2020-2023  润新知