你好,歡迎來到IOS教程網

 Ios教程網 >> IOS編程開發 >> IOS開發綜合 >> [IOS]Photo應用

[IOS]Photo應用

編輯:IOS開發綜合
IOS應用開發,如何加載圖片庫中的Image到view中?下面我們來學習一下吧! 操作步驟: 1.創建一個SingleView的項目,然後啟動模擬器,點擊模擬器上的浏覽器,然後將本地的圖片拖放上去,然後點擊圖片長按,點擊saveImage到圖片庫。 2.修改ViewController 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];  
    }  
}  

 


  1. 上一頁:
  2. 下一頁:
蘋果刷機越獄教程| IOS教程問題解答| IOS技巧綜合| IOS7技巧| IOS8教程
Copyright © Ios教程網 All Rights Reserved