iPhone开发 引用图片资源的三种方式
2013-10-17 09:52
127 查看
以一张图片为例 fakeXcode.png
下面以3种目录结构的方式引用这张图片:
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];
个人认为第二种最方便, 可以创建蓝色文件夹. 达到资源分组的目的!
下面以3种目录结构的方式引用这张图片:
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];
个人认为第二种最方便, 可以创建蓝色文件夹. 达到资源分组的目的!
相关文章推荐
- iPhone开发 引用图片资源的三种方式
- C# WinForm开发系列之DataGridView部分属性总结和图片资源的引用方式
- iPhone开发之创建简单界面视图的三种方式之二 使用Xcode4完全手动构建界面
- ios开发webview 的三种引用方式以及动态更新本地静态页的方法
- js replace 全局替换 以表单的方式提交参数 判断是否为ie浏览器 将jquery.qqFace.js表情转换成微信的字符码 手机端省市区联动 新字体引用本地运行可以获得,放到服务器上报404 C#提取html中的汉字 MVC几种找不到资源的解决方式 使用Windows服务定时去执行一个方法的三种方式
- android开发之获取图片资源的4种方式
- iOS引用图片文件的三种方式
- 前段CSS的三种引用方式,实际开发用第1种
- iPhone、iPad开发之图片资源管理
- Eclipse插件开发:Eclipse中的图片资源管理(引用)
- Android 音视频开发(一) : 通过三种方式绘制图片
- iPhone开发之创建简单界面视图的三种方式之一 使用xcode4自动生成界面
- Android开发之--图片压缩的三种方式
- Eclipse插件开发:Eclipse中的图片资源管理(引用)
- android获得图片资源的三种方式
- WPF开发学习:资源在内外部定义的不同方式和怎么引用,Style样式的四种使用(对比CSS)
- Qt中(图片)资源的三种使用方式
- Windows Phone - 引用图片资源的方式可能会影响图片显示质量
- ios开发webview 的三种引用方式以及动态更新本地静态页的方法
- android获得图片资源的三种方式