/*** 打开照相机*/
- (void)openCamera
{
if (![UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) return;
UIImagePickerController *ipc = [[UIImagePickerController alloc] init];
ipc.sourceType = UIImagePickerControllerSourceTypeCamera;
ipc.delegate = self;
[self presentViewController:ipc animated:YES completion:nil];
}
打开相册和打开相机的代码类似。
#pragma mark - UIImagePickerControllerDelegate
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
[picker dismissViewControllerAnimated:YES completion:nil];
// 1.取出选中的图片 返回的是字典,通过key取到图片。
UIImage *image = info[UIImagePickerControllerOriginalImage];
// 2.添加图片到相册中
[self.photosView addImage:image];
}
- (void)addImage:(UIImage *)image
{
UIImageView *imageView = [[UIImageView alloc] init];
imageView.contentMode = UIViewContentModeScaleAspectFill;//
imageView.clipsToBounds = YES;//有一定的剪切效果。
imageView.image = image;
[self addSubview:imageView];
}
// 添加显示图片的相册控件
- (void)setupPhotosView
{
HMComposePhotosView *photosView = [[HMComposePhotosView alloc] init];
photosView.width = self.textView.width;
photosView.height = self.textView.height;
photosView.y = 70;
[self.textView addSubview:photosView];
self.photosView = photosView;
}
联系客服