[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];  
    }  
}  

 


    发表评论
    请自觉遵守互联网相关的政策法规,严禁发布色情、暴力、反动的言论。
    用户名: 验证码:点击我更换图片
    最新评论 更多>>

    推荐热点

    • Lexical or Preprocessor Issue 'xxx.h
    • ios学习笔记(二)xcode 4.3.2下实现基本交互
    • ios学习笔记(一)xcode 4.3.2下创建第一个ios项目
    • UITableView一些方法
    • IOS类似iphone通讯录TableView的完整demo【附源码】
    • ios版本的helloworld
    • iPhone SDK开发:本地文本文件内容的读取
    • 如何为Iphone应用创建启动界面
    • 去掉屏幕键盘的方法
    网站首页 - 友情链接 - 网站地图 - TAG标签 - RSS订阅 - 内容搜索
    Copyright © 2008-2015 计算机技术学习交流网. 版权所有

    豫ICP备11007008号-1