iOS之Settings.Bundle的應用

 

Settings.Bundle

 

Settings.Bundle支持六種配置項分別是:Title,MultiValue,Group,Slider,ToggleSwitch,TextField 。api

 

Title

 

 

 

 

Type:配置類型,默認是Title
Title:配置項顯示的Title
Identifier: 配置項的標識符,用來獲取配置項的配置內容
Default Value :配置項默認值數組

MultiValue

 
 
Type:配置類型,默認Multi Value

Title:配置項顯示的標題
Identifier:配置項標識符,用來獲取配置項的配置內容
Default:配置項默認值
Titles:顯示的標題數組
Values:顯示的值數組,與Titles一一對應app


Group

 

Type,Title 同上;ide

TextField

 
 
Text Field Is Secure:是否密文顯示
KeyBoard Type:鍵盤類型
Autocapitalization Stylele:自動大寫
Autocorrection Style:自動糾正拼寫

ToggleSwitch

 

Slider

 
 

Minimum Value:最小值
Maximun Value:最大值
Min Value Image Filename:最小值端圖片
Max Value Image Filename:最大值端圖片spa

如何設置

1.New File ->Settings.Bundle3d

 

在右側的目錄會看到:orm

 
 

在Root.plist裏面添加上面說的配置項目:blog

 
 
 
配置好後,運行項目,而後在設置中點擊app,效果以下:


 

程序中獲取配置信息

獲取配置信息其實很簡單,直接上代碼:圖片

//獲取SettingsBundle信息
    NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
    
    NSLog(@"%@",[userDefaults objectForKey:@"title_perference"]);
    NSLog(@"%@",[userDefaults objectForKey:@"sex_perference"]);
    NSLog(@"%@",[userDefaults objectForKey:@"name_preference"]);
    NSLog(@"%@",[userDefaults objectForKey:@"enabled_preference"]);
    NSLog(@"%@",[userDefaults objectForKey:@"slider_preference"]);

 

這裏有一點須要說明: 若是運行應用後直接直接經過上面的代碼獲取信息,你會獲得null;緣由是: root.plist實際上只是一個靜態文件用來在設置裏顯示;只有當你對它進行修改,它纔會往NSUserDefaults裏添加。修改配置後,NSUserDefaults的優先級高於root.plist文件。
相關文章
相關標籤/搜索