/**< 写入2倍和3倍图片到沙盒 */
- (NSString *)configTabbarItemImageWithUrl:(NSString *)imageUrl {
NSArray *stringArray = [imageUrl componentsSeparatedByString:@"/"];
NSString *imageName = stringArray.lastObject;
NSArray *tempArray = [imageName componentsSeparatedByString:@"."];
NSString *newImageName = tempArray.firstObject;
NSString *doubleImageName = nil;
NSString *tripleImageName = nil;
if ([newImageName haveValueString]) {
doubleImageName = [NSString stringWithFormat:@"%@@2x.png",newImageName];
tripleImageName = [NSString stringWithFormat:@"%@@3x.png",newImageName];
}
UIImage *loadImage = [UIImage sd_imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:imageUrl]]];
NSArray *pathArray = (NSArray *)NSSearchPathForDirectoriesInDomains(NSCachesDirectory,NSUserDomainMask,YES);
NSString *path = pathArray.firstObject;
NSString *doublefilePath = [path stringByAppendingPathComponent:doubleImageName];
NSString *triplefilePath = [path stringByAppendingPathComponent:tripleImageName];
if ([UIImagePNGRepresentation(loadImage) writeToFile:doublefilePath atomically:YES]) {
XLog(@"写入2倍图片成功")
}
if ([UIImagePNGRepresentation(loadImage) writeToFile:triplefilePath atomically:YES]) {
XLog(@"写入3倍图片成功")
}
return [NSString stringWithFormat:@"%@/%@.png",path,newImageName];
}
网友评论