• 访问相册, 从相册中选取图片


    @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

  • 相关阅读:
    squid反向代理
    LVM逻辑卷管理
    磁盘分区
    磁盘阵列
    apache基本配置
    LNMP简要配置
    高性能Web服务器Nginx
    samba文件共享服务配置(multiuser机制)二 (共两节)
    samba文件共享服务配置一(共2节)
    linux 批量修改文件名 文件名只保留部分,去掉部分
  • 原文地址:https://www.cnblogs.com/hsxblog/p/4948361.html
Copyright © 2020-2023  润新知