使用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;
}
上一篇:微信公共号url地址出错,调用上次设置地址.


下一篇:Mybatis3——使用学习(二)