码迷,mamicode.com
首页 > 其他好文 > 详细

获取系统相册图片进行九宫布局

时间:2016-05-21 21:37:49      阅读:101      评论:0      收藏:0      [点我收藏+]

标签:

- (void)openCamera

{

    NSLog(@"打开相机");

    [self imagePickerControllerType:UIImagePickerControllerSourceTypeCamera];

}

 - (void)imagePickerControllerType:(UIImagePickerControllerSourceType)sourceType

{

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

    pickerController.sourceType = sourceType;

    pickerController.delegate = self;

    [self.navigationController presentViewController:pickerController animated:YES completion:nil];

}

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary<NSString *,id> *)info

{

    // 获取当前点击的图片名字

    UIImage *imageName = info[UIImagePickerControllerOriginalImage];

    [self.publishPhotoView addPhotoName:imageName];

    [self dismissViewControllerAnimated:YES completion:nil];

}

 

在自己定义PhotoView中进行布局

- (void)layoutSubviews {

    [super layoutSubviews];

    // 设置图片的尺寸和位置

    NSUInteger count = self.subviews.count;

    int maxCol = 4;

    CGFloat imageWH = 70;

    CGFloat imageMargin = 10;

     for (int i = 0; i<count; i++) {

        UIImageView *photoView = self.subviews[i];

        int col = i % maxCol;

        photoView.x = col * (imageWH + imageMargin);

        

        int row = i / maxCol;

        photoView.y = row * (imageWH + imageMargin);

        photoView.width = imageWH;

        photoView.height = imageWH;

    }

}

 - (void)addPhotoName:(UIImage *)photpName

{

    UIImageView *photo = [[UIImageView alloc] init];

    photo.backgroundColor = [UIColor yellowColor];

    [self addSubview:photo];

    

    photo.image = photpName;

}

 

获取系统相册图片进行九宫布局

标签:

原文地址:http://www.cnblogs.com/happyEveryData/p/5515502.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!