UIimage 加载图片

来源:互联网 发布:软件系统项目总结 编辑:程序博客网 时间:2024/03/28 18:13
图片缓存

根据是否将创建好的对象缓存入系统内存,有两类创建UIImage对象的方法可选:

缓存:+ imageNamed:,只需传入文件名.扩展名(可选)即可。

不缓存:+ imageWithContentsOfFile:,必须传入文件的全名(全路径+文件名)。


@2x和@3x的问题

使用initWithContentsOfFile可以优先选择3x图像,而不是2x图像。

NSString *path = [[NSBundlemainBundle]pathForResource:@"smallcat"ofType:@"png"];

UIImage *image = [[UIImagealloc]initWithContentsOfFile:path];

在ipone5 s、iphone6和iphone6 plus都是优先加载@3x的图片,如果没有@3x的图片,就优先加载@2x的图片


这个方法

[UIImageimageNamed:@"smallcat"]

iphone5s和iphone6优先加载@2x的图片,iphone6 plus是加载@3x的图片。



@2x表示一个点内含2*2个像素,@3x表示一个点内含3*3个像素


0 0
原创粉丝点击