国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 系統 > iOS > 正文

iOS archive保存圖片到本地的方法

2019-10-21 18:47:17
字體:
來源:轉載
供稿:網友

本文實例為大家分享了iOS保存圖片到本地的具體代碼,供大家參考,具體內容如下

一、工程圖

iOS,archive保存圖片到本地,iOS保存圖片到本地,iOS保存圖片

二、代碼

RootViewController.h

#import <UIKit/UIKit.h>@interface RootViewController : UIViewController{ UIImageView *imageView;}@end

RootViewController.m

#import "RootViewController.h"@interface RootViewController ()@end@implementation RootViewController- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil{ self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; if (self) {  // Custom initialization } return self;}- (void)viewDidLoad{ [super viewDidLoad]; // Do any additional setup after loading the view.  //初始化背景圖 imageView=[[UIImageView alloc]initWithFrame:CGRectMake(100, 100, 100, 100)]; imageView.backgroundColor=[UIColor redColor]; [self.view addSubview:imageView];  //將圖片保存 [self archive];  //提取保存在本地的圖片 [self unarchive]; }#pragma -mark -functions//歸檔-(void)archive{ NSData *data=[NSKeyedArchiver archivedDataWithRootObject:[UIImage imageNamed:@"1.jpg"]]; NSUserDefaults *imageDefault = [NSUserDefaults standardUserDefaults]; [imageDefault setObject:data forKey:@"image"]; [imageDefault synchronize];}//反歸檔-(void)unarchive{ NSData* data = [[NSUserDefaults standardUserDefaults]objectForKey:@"image"]; id image= [NSKeyedUnarchiver unarchiveObjectWithData:data]; imageView.image=image; }

以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持VEVB武林網。


注:相關教程知識閱讀請移步到IOS開發頻道。
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 白朗县| 临西县| 临桂县| 策勒县| 凤庆县| 凤山县| 伊宁市| 晴隆县| 利津县| 深泽县| 华蓥市| 岗巴县| 天镇县| 印江| 靖安县| 崇礼县| 铜鼓县| 融水| 伊宁县| 营山县| 克东县| 乌海市| 新民市| 东乡族自治县| 古丈县| 葫芦岛市| 综艺| 丰顺县| 尼木县| 满城县| 南召县| 仁寿县| 弋阳县| 德阳市| 通江县| 安龙县| 武川县| 无为县| 玛多县| 娄烦县| 武乡县|