转载自:http://code4app.com/snippets/one/%E8%8E%B7%E5%8F%96%E5%9B%BE%E7%89%87%E6%96%B9%E6%B3%95/508f76966803fa446c000000#s1
获取图片方法
1
2
3
4
5
6
|
建议使用该方法获取图片
NSString
*imagePath = [[
NSBundle
mainBundle
]
pathForResource
:
@"sun"
ofType
:
@"png"
];
UIImage
*image = [[
UIImage
alloc
]
initWithContentsOfFile
:imagePath];
不要使用下面的方法,图片过大容易造成内存溢出
UIImage
*image = [
UIImage
imageNamed
:
@"sun.png"
];
|
-
12345678
/**
*如果图片只用一次或很少,用这个方法不放在缓存里
*/
NSString
*imagePath = [[
NSBundle
mainBundle
]
pathForResource
:
@"sun"
ofType
:
@"png"
];
/**
*如果图片多次用到,用这个方法放在缓存效率更高~
*/
UIImage
*image = [
UIImage
imageNamed
:
@"sun.png"
];