今天刚好就看到了这三种方式,感觉肯定有人用的着就转载过来了
原文地址: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
本文采用知识共享署名4.0 国际许可协议进行许可。转载或大段使用必须添加本文链接,否则您将构成侵权!