3 plist-->data-->数组/字典
NSData *courseListData = [NSData dataWithContentsOfFile:([[NSBundle mainBundle] pathForResource:@"quiz_course_list" ofType:@"plist"])];
if (courseListData) {
self.coursePlist = [NSDictionary dictionaryWithPlistData:courseListData];
//dictionaryWithPlistData:该方法是yykit的方法
}
NSString *pathList = [[NSBundle mainBundle]pathForResource:@"ChinaRegion" ofType:@"plist"];
NSArray *listArray = [NSArray arrayWithContentsOfFile:pathList];
NSLog(@"%@",listArray);
4 data-->array/dictionary
//路径文件(json)-->data
NSString *path = [[NSBundle mainBundle]pathForResource:@"answer" ofType:@"json"];
NSData *data = [NSData dataWithContentsOfFile:path];
//data-->array/dictionary
NSArray *arr = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:nil];
NSLog(@"arr = %@",arr);
//路径文件(plist)-->data-->arr/dic
NSString *path = [[NSBundle mainBundle]pathForResource:@"grade_list_cn" ofType:@"plist"];
self.gradeDic = [NSDictionary dictionaryWithPlistData:[NSData dataWithContentsOfFile:path]];
5 UIimage
//image -->data
UIImage *image =[UIImage imageNamed:@""];
NSData *pngData =UIImagePNGRepresentation(image);
NSData *jpegdata = UIImageJPEGRepresentation(image, 1);//compressionQuality:压缩质量,1代表质量最高
//data-->image
NSData *imageData = [NSData dataWithContentsOfFile:@"imagePath"];
UIImage *image1 = [UIImage imageWithData:imageData];
6加载网络图片
//1 阻塞线程
NSURL *url = [NSURL URLWithString:@"https://ubmcmm.baidustatic.com/media/v1/0f000nKyy1AN5J31jAVuE0.jpg"];
NSData *urlimageData =[NSData dataWithContentsOfURL:url];
UIImage *urlimage = [UIImage imageWithData:urlimageData];
self.urlImageView.image = urlimage;
//2 异步加载
NSOperationQueue *operationQ = [[NSOperationQueue alloc]init];
NSInvocationOperation *op = [[NSInvocationOperation alloc] initWithTarget:self selector:@selector(downloadImage) object:nil];
[operationQ addOperation :op];
//3使用SDWebImage
[imageView sd_setImageWithURL:imageUrl];
//注意:有的url有中文字符,需要进行转义
NSString *str = @"https://upload.jianshu.io/admin_banners/web_images/4570/5d4776585f0206ff2e807971a13b06ed7d494595.jpg?imageMogr2/auto-orient/strip|imageView2/1/w/1250/h/540";
NSString *str1 = [str stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]];
[headerImageV sd_setImageWithURL:[NSURL URLWithString:str1]];
网友评论