今天刚好就看到了这三种方式,感觉肯定有人用的着就转载过来了
原文地址: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];
版权属于:东哥笔记 - DongGe.org
本文链接:https://dongge.org/blog/20.html
自2017年12月26日起,『转载以及大段采集进行后续编辑』须注明本文标题和链接!否则禁止所有转载和采集行为!