工程中添加Resource->Setting Bundle

相关资料:https://developer.apple.com/library/iOS/#documentation/Cocoa/Conceptual/UserDefaults/Introduction/Introduction.html

1、与工程中添加Resource->Setting Bundle
创建
文件说明:
en.lproj为多语言配置目录该目录的strings文件只有在IOS系统语言环境与文件夹想符才能读取。
Root.plist为Setting页面的根目录配置文件。
此时编译运行后已经能够看到通用设置中对应程序的Setting。

2、Setting页面制作Root.plist
Root.plist组成:
PreferenceSpecifiers 包含Setting页面中的子项
Strings Filename 指定多语言环境下的strings文件对应语言环境生效
StringsTable 指定strings文件直接生效


以下是一个Setting设置plist例子

Root.plist

[html] view plain copy
  
  
  
  
    PreferenceSpecifiers  
      
          
            Type  
            PSGroupSpecifier  
            Title  
            Sound  
          
          
            Type  
            PSToggleSwitchSpecifier  
            Title  
            Play Sound  
            Key  
            play_sound_preference  
            DefaultValue  
              
          
          
            Type  
            PSToggleSwitchSpecifier  
            Title  
            3D Sound  
            Key  
            3D_sound_preference  
            DefaultValue  
              
          
          
            Type  
            PSGroupSpecifier  
            Title  
            User Info  
          
          
            Type  
            PSTextFieldSpecifier  
            Title  
            Name  
            Key  
            user_name  
          
          
            Type  
            PSMultiValueSpecifier  
            Title  
            Experience Level  
            Key  
            experience_preference  
            DefaultValue  
            0  
            Titles  
              
                Beginner  
                Expert  
                Master  
              
            Values  
              
                0  
                1  
                2  
              
          
          
            Type  
            PSGroupSpecifier  
            Title  
            Gravity  
          
          
            Type  
            PSSliderSpecifier  
            Key  
            gravity_preference  
            DefaultValue  
            1  
            MinimumValue  
            0  
            MaximumValue  
            2  
          
          
            Type  
            PSGroupSpecifier  
            Title  
            Other  
          
          
            File  
            Other  
            Type  
            PSChildPaneSpecifier  
            Title  
            Other Setting  
            Key  
            other_setting  
          
      
    Strings Filename  
    Root  
  
  

Other.plist(直接复制Root.plist更改Item的Key)
[html] view plain copy

  
  
  
  
    PreferenceSpecifiers  
      
          
            Type  
            PSGroupSpecifier  
            Title  
            Sound  
          
          
            Type  
            PSToggleSwitchSpecifier  
            Title  
            Play Sound  
            Key  
            oplay_sound_preference  
            DefaultValue  
              
          
          
            Type  
            PSToggleSwitchSpecifier  
            Title  
            3D Sound  
            Key  
            o3D_sound_preference  
            DefaultValue  
              
          
          
            Type  
            PSGroupSpecifier  
            Title  
            User Info  
          
          
            Type  
            PSTextFieldSpecifier  
            Title  
            Name  
            Key  
            ouser_name  
          
          
            Type  
            PSMultiValueSpecifier  
            Title  
            Experience Level  
            Key  
            oexperience_preference  
            DefaultValue  
            0  
            Titles  
              
                Beginner  
                Expert  
                Master  
              
            Values  
              
                0  
                1  
                2  
              
          
          
            Type  
            PSGroupSpecifier  
            Title  
            Gravity  
          
          
            Type  
            PSSliderSpecifier  
            Key  
            ogravity_preference  
            DefaultValue  
            1  
            MinimumValue  
            0  
            MaximumValue  
            2  
          
      
    Strings Filename  
    Root  
  
  

3、读取Setting配置
Setting是以Key Value的形式存储在NSUserDefaults中所以当Setting配置文件Key相同时会相互影响。

[cpp] view plain copy
NSUserDefaults *userdefaults = [NSUserDefaults standardUserDefaults];
//[userdefaults valueForKey:(NSString *)];//根据Key获取数据
Setting变更同步注册通知

[cpp] view plain copy
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(change) name:@"NSUserDefaultsDidChangeNotification" object:nil];

你可能感兴趣的:(工程中添加Resource->Setting Bundle)