zoukankan      html  css  js  c++  java
  • 访问相册, 从相册中选取图片

    @interface OneViewController ()<UIImagePickerControllerDelegate, UINavigationControllerDelegate>{

        UIImageView *imageView;

    }

    @end

    @implementation OneViewController

    - (void)viewDidLoad {

        [super viewDidLoad];

        self.view.backgroundColor = [UIColor yellowColor];

        

        

        //UIImageView 继承于UIView

        imageView = [[UIImageView alloc] initWithFrame:CGRectMake(50, 50, 100, 150)];

        imageView.backgroundColor = [UIColor grayColor];

        [self.view addSubview:imageView];

        

        UIButton *button = [UIButton buttonWithType:(UIButtonTypeCustom)];

        button.frame = CGRectMake(100, 200, 100, 100);

        button.layer.cornerRadius = 50;

        [button addTarget:self action:@selector(camera) forControlEvents:(UIControlEventTouchUpInside)];

        [button setTitle:@"相机" forState:(UIControlStateNormal)];

        [self.view addSubview:button];

        button.backgroundColor = [UIColor redColor];

        

        UIButton *mButton = [UIButton buttonWithType:(UIButtonTypeCustom)];

        mButton.frame = CGRectMake(50, 400, 100, 50);

        [mButton addTarget:self action:@selector(photo) forControlEvents:(UIControlEventTouchUpInside)];

        mButton.backgroundColor = [UIColor redColor];

        [mButton setTitle:@"相册" forState:(UIControlStateNormal)];

        [self.view addSubview:mButton];

    }

    - (void)camera {

        //判断是否由摄像头

        BOOL isCamera = [UIImagePickerController isCameraDeviceAvailable:(UIImagePickerControllerCameraDeviceRear)];

    //UIImagePickerControllerCameraDeviceRear后置摄像头

     //前置摄像头UIImagePickerControllerCameraDeviceFront

        if (!isCamera) {

            NSLog(@"没有后置摄像头");

            return;

        }

        UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];

        imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera;

        imagePicker.delegate = self;

        imagePicker.editing = YES;//相机照的照片是否允许编辑

        [self presentViewController:imagePicker animated:YES completion:^{

        }];

        

    }

    //调取相册

    - (void)photo {

        UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];

        imagePicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;

        [self presentViewController:imagePicker animated:YES completion:^{

            NSLog(@"打开系统相册");

        }];

        imagePicker.delegate = self;

        [imagePicker release];

    }

    - (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingImage:(UIImage *)image editingInfo:(NSDictionary *)editingInfo {

        //选取相册照片

        imageView.image = image;

        [self dismissViewControllerAnimated:YES completion:^{

        }];

    }

    - (void)didReceiveMemoryWarning {

        [super didReceiveMemoryWarning];

        // Dispose of any resources that can be recreated.

    }

    @end

  • 相关阅读:
    字符串,format格式化及列表的相关进阶操作---day07
    利用wiile双层循环打印各种星星---day06
    双层循环练习,pass_break_continue,和for循环---day06
    类型判断,代码块,流程控制及循环---day05
    频繁项集算法
    Unity 物体移动的理解
    Game1---游戏设计
    精读Hadamard Response论文
    java 创建线程
    Unity游戏开发面试基础知识
  • 原文地址:https://www.cnblogs.com/hsxblog/p/4948361.html
Copyright © 2011-2022 走看看