[IOS]Photo应用
来源:未知 责任编辑:责任编辑 发表时间:2015-10-08 14:15 点击:次
IOS应用开发,如何加载图片库中的Image到view中?下面我们来学习一下吧!
p>操作步骤:
p>1.创建一个SingleView的项目,然后启动模拟器,点击模拟器上的浏览器,然后将本地的图片拖放上去,然后点击图片长按,点击saveImage到图片库。
p>2.修改ViewController
p>ViewController.h:
#import <UIKit/UIKit.h> @interface DXWViewController : UIViewController<UIImagePickerControllerDelegate,UINavigationControllerDelegate> @property (retain, nonatomic) IBOutlet UIImageView *imageView; @property (retain, nonatomic) IBOutlet UIButton *Button; @property(retain,nonatomic) UIImage *image; - (IBAction)click:(id)sender; @end ViewController.m: [plain] view plaincopyprint? #import "DXWViewController.h" @interface DXWViewController () @end @implementation DXWViewController - (void)viewDidLoad { [super viewDidLoad]; } -(void)viewWillAppear:(BOOL)animated { self.imageView.image = self.image; } //加载成功 -(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info { self.Image = [info objectForKey:UIImagePickerControllerEditedImage]; [picker dismissViewControllerAnimated:YES completion:nil]; } //取消 -(void)imagePickerControllerDidCancel:(UIImagePickerController *)picker { [picker dismissViewControllerAnimated:YES completion:nil]; } - (void)dealloc { [_imageView release]; [_image release]; [_Button release]; [super dealloc]; } //打开图库获取图片 - (IBAction)click:(id)sender { if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypePhotoLibrary]) { UIImagePickerController *picker = [[UIImagePickerController alloc] init]; picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary; picker.delegate = self; picker.allowsEditing = YES; [self presentViewController:picker animated:YES completion:nil]; } }
相关新闻>>
最新推荐更多>>>
- 发表评论
-
- 最新评论 更多>>