1. xcode 集成了png优化工具 pngcrush,编译的时候可以png格式文件进行优化和压缩
build setting 搜 png
compress png files 设置为yes
2.压缩后png 一般会比jpeg 格式文件大,本地图片推荐使用png,网络图片下载使用jpeg
3.创建 UIImage对象
类构造方法 +imageNamed 会在内存中建立缓存,这些缓存直到应用停止才清除。如果贯穿这个应用的图片(图标/logo)推荐使用。
UIImage * image= [UIImage imageNamed:@"test.png"];
实例方法 -initWithContentsOfFile 使用一次的图片推荐
NSString * path = [[NSBundle mainBundle] pathForResource:@"test" ofType:@"png"];
UIImage * image= [[UIImage alloc] initWithContentsOfFile:path];
....
[image release];