iOS面试

iOS-imageNamed与imageWithContents

2018-10-14  本文已影响71人  路飞_Luck
iOS中根据本地icon加载出一个UIImage对象有两种方法:
UIImage *img =  [UIImage imageNamed:@"pic"];

*imageWithContentsOfFile:

NSString *filePath = [[NSBundle mainBundle] pathForResource:@"1" ofType:@"png"];
UIImage *img =  [UIImage imageWithContentsOfFile:filePath];
那么这两种方式有什么区别吗?
imageNamed:方法
优缺点
imageWithContentsOfFile:方法
优缺点

总结: 一些小的icon可以存在Assets里面。用imageNamed:加载。一些比较大的,使用频率低的可以建立一个bundle存放图片,使用imageWithContentsOfFile:加载。


本文参考iOS中imageNamed与imageWithContentsOfFile的区别,非常感谢该作者。



上一篇 下一篇

猜你喜欢

热点阅读