iOS使用本地图片创建imageview的三种方式

今天刚好就看到了这三种方式,感觉肯定有人用的着就转载过来了

原文地址:http://blog.sina.com.cn/s/blog_6a99c8bc01011ppj.html

1。直接拖进工程+copy

image = [UIImage imageNamed: @"fakeXcode.png"];
NSString *path = [[NSBundle mainBundle] pathForResource:@"fakeXcode" ofType:@"png"];
image = [[UIImage alloc]initWithContentsOfFile:path];


2.把文件夹拖进工程目录,然后拖进工程,create folder references for any added folder,(蓝色文件夹res)

image = [UIImage imageNamed: @"res/fakeXcode.png"];
NSString *path = [[NSBundle mainBundle] pathForResource:@"fakeXcode.png" ofType:nil inDirectory:@"res"];
image = [[UIImage alloc]initWithContentsOfFile:path];



3.创建bundle,把资源放进bundle(白色bundle,res.bundle)

image = [UIImage imageNamed: @"es.bundle/fakeXcode.png"];
NSString *path = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"res.bundle/fakeXcode.png"];
image = [[UIImage alloc]initWithContentsOfFile:path];


Last modification:January 1st, 1970 at 08:00 am
如果看了这个文章可以让你少加会班,可以请我喝杯可乐
已打赏名单
微信公众号

Leave a Comment