标签:
- (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