Bundle in Ios~
来源:互联网 发布:年均增速算法 编辑:程序博客网 时间:2024/05/17 14:18
Bundle简单地讲,就是一个内部结构按照标准规则组织的特殊目录。
用途主要是软件的国际化,类似如java .property等一些文件的作用。
场景:软件有美国、中国版本,软件的logo等图片不同,这时候,我们把相应的图片资源放到一个文件夹下,然后修改文件夹的名字.bundle,然后添加到xcode中。
我们知道每个project都有个mainBundle,那如何去获取自己定义的bundle内容呢?
我们把自定义的bundle当成项目的一种资源,由mainBundle去获取~,然后我们用相同的方式获取自定义的bundle下的资源。
过程:
1、通过mainBundle去加载自定义的bundle
2、通过获取到的自定义bundle去获取资源
在这里,我们根据上述场景来写个demo。
项目的结构如下:
注:America.bundle和China.bundle分别代表不同软件版本的资源包。
在AvatarImage.xib中我们会根据软件版本显示不同的图片。
AvatarImage.m部分代码:
#pragma mark 根据国家来选择图片展示
- (void)showImages:(NSString *)country
{
if (nil != country && country.length > 0)
{
NSString *resourcePath = [[NSBundle mainBundle] pathForResource:country ofType:@"bundle"];
if (resourcePath.length > 0)
{
NSBundle *countryBundle = [[NSBundlealloc] initWithPath:resourcePath];
NSString *avatarPath = [countryBundle pathForResource:@"avatar"ofType:@"png"];
if (avatarPath.length > 0)
{
UIImage *image = [UIImage imageWithContentsOfFile:avatarPath];
[avatarImage setImage:image];
}
else
{
NSLog(@"The avatar image not found~~");
}
}
else
{
NSLog(@"The country resource not found~~");
}
}
}
#pragma mark - View lifecycle
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
[self showImages:@"America"];
}
America的view截图:
China的截图:
抛砖引玉~~记录下自己学的
出自:http://avatar-matrix.lofter.com/post/e4689_236e82
- Bundle in Ios~
- Bundle in IOS
- ios bundle
- iOS bundle
- Unit Test Bundle' in SDK 'iOS 8.1 解决方法
- iOS-XIB Could not load NIB in bundle
- gem,bundle in rails
- Bundle class in android
- ios Bundle的使用
- ios Settings Bundle简介
- [IOS]Setting Bundle + StoryBoard
- iOS bundle文件
- .bundle文件 - iOS开发
- iOS setting bundle
- iOS-生成Bundle包
- iOS Bundle详解
- iOS开发 .bundle使用
- iOS bundle打包教程
- LeetCode Convert Sorted Array to Binary Search Tree
- 同一个%的不同答案
- APP被苹果APPStore拒绝的各种原因
- 数据结构第七章思维导图
- jquery 选中radio 与取消radio选中状态
- Bundle in Ios~
- 需求分析到设计
- quik讲解-2
- 关于设置tableView的背景图片
- oracle修改最大连接数
- 分布式文件系统的存储节点和追踪器
- .net 获取当前月份天数的几种实现方法
- 借助Intent实现Android工程中Activity之间Java对象的传递——实现Serializable接口
- Android中Scrollview、ViewPager冲突问题汇总(已解决)