使用ImageView

时间:2023-03-09 13:24:49
使用ImageView
@property (strong, nonatomic) UIPopoverController *pop;
//选取图片
- (IBAction)selectImage:(UIButton *)sender
{
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypePhotoLibrary])
{
picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
picker.delegate = self; self.pop = [[UIPopoverController alloc] initWithContentViewController:picker];
self.pop.delegate = self;
[self.pop presentPopoverFromRect:sender.frame inView:self.view permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
}
}

实现UIImagePickerController委托方法:

-(void)imagePickerControllerDidCancel:(UIImagePickerController *)picker
{
[self.pop dismissPopoverAnimated:YES];
} -(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
UIImage *image = [info valueForKey:@"UIImagePickerControllerOriginalImage"];
self.masterViewController.mainImage = image;
self.imageView.image = image;
[self.pop dismissPopoverAnimated:YES];
}

实现clearImage:方法,实现视图重设。

- (IBAction)clearImage:(id)sender
{
self.imageView.image = nil;
self.masterViewController.mainImage = nil;
}