iOS开发中Settings.bundle的使用
来源:互联网 发布:linux ssh 目录结构图 编辑:程序博客网 时间:2024/05/16 10:19
在iOS开发中很多时候开发者需要让用户自行设置一些系统的配置项目,比如让用户设置是否支持在3G模式下加载数据,或者是让用户自己设置支不支持网络数据缓存的功能。另外在企业级应用开发中经常有需要对后台的访问地址进行调整那么需要用户自行的进行配置,下面是爱奇艺和招商银行的设置配置项:
Settings.bundle配置说明
在Settings.bundle中支持如下几种配置项:
1、Group
Group类似于UITableView中的Group分组,用来表示一组设置项,配置如下所示:
配置项说明:
(1)Title:表示分组的显示标题
(2)Type:默认是Group
(3)FooterText:Group的底部显示的文字内容
2、Multi Value
Multi Value
是为了让用户在多个值中选择需要的内容,相当于下拉列表的形式进行选择,配置如下所示:
配置项说明:
(1)Type:默认是Multi Value
(2)Title:配置项显示的标题
(3)Identifier:设置项的标识符,用于读取配置项的配置内容
(4)Default Value:默认的值,对应的是Values中的项目
(5)Titles:显示的标题的集合
(6)Values:显示的值的集合,与标题一一对应
3、Slider
配置项说明:
(1)Type:配置类型,默认是Slider
(2)Identifier:设置项的标识符,用于读取配置项的配置内容
(3)Default Value:默认值,Number类型
(4)Minimum Value:最小值,Number类型
(5)Maximum Value:最大值,Number类型
(6)Max Value Image Filename:最大值那一端的图片。
(7)Min Value Image Filename:最小值那一端的图片。
4、Text Field
配置项说明:
(1)Text Field is Secure:是否为安全文本。如果设置为YES,则内容以圆点符号出现。
(2)Autocapitalization Style:自动大写。有四个值: None(无)
、Sentences(句子首字母大写)
、Words(单词首字母大写)
和All Characters(所有字母大写)
。
(3)Autocorrection Style:自动纠正拼写,如果开启,你输入一个不存在的单词,系统会划红线提示。有三个值:Default(默认)
、No Autocorrection(不自动纠正)
和Autocorrection(自动纠正)
。
(4)Keyboard Type:键盘样式。有五个值:Alphabet(字母表,默认)
、Numbers and Punctuation(数字和标点符号)
、Number Pad(数字面板)
、URL(比Alphabet多出了.com等域名后缀)
和Email Address(比Alphabet多出了@符合)
。
5、Title
配置项说明:
(1)Type:默认是Title
(2)Title:配置项显示的标题
(3)Identifier:设置项的标识符,用于读取配置项的配置内容
(4)Default Value:默认的值
6、Toggle Switch
Toggle Switch
是一个类似于UISwitch的选项,用于设置简单的开启或者关闭的选项,配置如下所示:
配置项说明:
(1)Type:默认是Toggle Switch
(2)Title:配置项显示的标题
(3)Identifier:设置项的标识符,用于读取配置项的配置内容
(4)Default Value:默认的值
在项目中使用
1、添加Setting.bundle文件到项目中
2、读取配置信息
- (void)readingPreference{ //获取Settings.bundle路径 NSString *settingsBundle = [[NSBundle mainBundle] pathForResource:@"Settings" ofType:@"bundle"]; if(!settingsBundle) { NSLog(@"找不到Settings.bundle文件"); return; } //读取Settings.bundle里面的配置信息 NSDictionary *settings = [NSDictionary dictionaryWithContentsOfFile:[settingsBundle stringByAppendingPathComponent:@"Root.plist"]]; NSArray *preferences = [settings objectForKey:@"PreferenceSpecifiers"]; NSMutableDictionary *defaultsToRegister = [[NSMutableDictionary alloc] initWithCapacity:[preferences count]]; for(NSDictionary *prefSpecification in preferences) { NSString *key = [prefSpecification objectForKey:@"Key"]; if(key) { [defaultsToRegister setObject:[prefSpecification objectForKey:@"DefaultValue"] forKey:key]; } } [[NSUserDefaults standardUserDefaults] registerDefaults:defaultsToRegister]; [[NSUserDefaults standardUserDefaults] synchronize]; //TODO:读取指定数据}
3、在AppDelegate中读取配置信息
(1)应用启动后读取配置信息
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions{ self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; //读取配置文件 [[SystemConfigHelper shared] readingPreference]; self.window.backgroundColor = [UIColor whiteColor]; [self.window makeKeyAndVisible]; return YES;}
(2)应用程序进入到前台后读取配置信息
- (void)applicationWillEnterForeground:(UIApplication *)application{ //读取配置信息 [[SystemConfigHelper shared] readingPreference];}
说明:
SystemConfigHelper
是用来读取系统配置信息的工具.
典型实例
1、爱奇艺iPhone客户端的Settings.bundle配置
2、招商银行iPhone客户端的Settings.bundle配置
参考资料
1、《整合Settings.bundle显示版本信息》
2、《应用程序首选项(application preference)及数据存储》
3、《设置束(Setting Bundle)的使用》
4、《三十而立,从零开始学ios开发(十九):Application Settings and User Defaults(上)》
- iOS开发中Settings.bundle的使用
- iOS开发中Settings.bundle的使用
- ios开发中 应用设置的简单开发 (Settings.bundle)
- ios开发中 应用设置的简单开发 (Settings.bundle)
- iOS开发之iOS程序偏好设置(Settings Bundle)的使用
- iOS开发之iOS程序偏好设置(Settings Bundle)的使用
- iOS开发之iOS程序偏好设置(Settings Bundle)的使用
- iOS开发之iOS程序偏好设置(Settings Bundle)的使用
- iOS开发之iOS程序偏好设置(Settings Bundle)的使用
- iOS开发之iOS程序偏好设置(Settings Bundle)的使用
- iOS开发之iOS程序偏好设置(Settings Bundle)的使用
- iOS开发之iOS程序偏好设置(Settings Bundle)的使用
- iOS开发之iOS程序偏好设置(Settings Bundle)的使用
- iOS开发之iOS程序偏好设置(Settings Bundle)的使用
- iOS开发之iOS程序偏好设置(Settings Bundle)的使用
- iOS中bundle的使用
- ios Settings Bundle简介
- iOS之Settings.Bundle
- java之二分法递归显示数列
- nodejs,npm appium win7安装过程
- Fast unfolding of communities in large networks
- JavaScript--表单的序列化
- 最全动画教程实例-实现简单的树形动画效果
- iOS开发中Settings.bundle的使用
- 桌面快速启动软件AltRun----赶快使得你的桌面变整洁吧
- linux下开发的头文件
- Python学习小记2
- 关于View的获取位置的api
- 查找指定端口被哪个进程占用&&恢复删除的文件
- Lombok使用说明
- Unity学习笔记15——Unity5之后的AssetBundle使用方法
- 项目经理是失败的根源?