zoukankan      html  css  js  c++  java
  • 调用相册

     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
  • 相关阅读:
    [PoC]某B2B网站的一个反射型XSS漏洞
    Python中的基本语句
    视频: 千重浪Linux系统调试技术培训 03-01_Basic-CPU-Register
    POJ 2955 Brackets (区间dp 括号匹配)
    LeetCode 146 LRU Cache
    Poj1734题解
    Python
    小胖说事29-----iOS中Navigation中左滑pop页面的三种方法
    深入理解javascript之原型
    android 弹幕评论效果
  • 原文地址:https://www.cnblogs.com/hanweifeng/p/5190497.html
Copyright © 2011-2022 走看看