溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點(diǎn)擊 登錄注冊 即表示同意《億速云用戶服務(wù)條款》

[IOS]Photo應(yīng)用

發(fā)布時(shí)間:2020-07-12 03:40:25 來源:網(wǎng)絡(luò) 閱讀:310 作者:蓬萊仙羽 欄目:移動(dòng)開發(fā)

IOS應(yīng)用開發(fā),如何加載圖片庫中的Image到view中?下面我們來學(xué)習(xí)一下吧!

操作步驟:

1.創(chuàng)建一個(gè)SingleView的項(xiàng)目,然后啟動(dòng)模擬器,點(diǎn)擊模擬器上的瀏覽器,然后將本地的圖片拖放上去,然后點(diǎn)擊圖片長按,點(diǎn)擊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:

#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];     } } @end


運(yùn)行結(jié)果:

[IOS]Photo應(yīng)用[IOS]Photo應(yīng)用[IOS]Photo應(yīng)用[IOS]Photo應(yīng)用

demo文件:http://download.csdn.net/detail/s10141303/6037575

向AI問一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI