iOS 開發指南 第12章 應用程式設定

來源:互聯網
上載者:User

標籤:

1 概述

   設定中的項目在應用中是不經常變化的,它決定了應用的基本特徵和行為。

   配置是在應用內部開闢出來的功能塊,是應用的一部分,項目是經常變化的。

2 應用程式設定包

   Settings Bundle是一個包檔案,其中含有設定介面中所需的項目的描述 用到的照片 文字的本地化 子設定項目的描述等內容。通過finder開啟。

   Root.plist檔案描述根設定介面中設定的項目資訊。

   en.lproj檔案夾和Root.strings檔案是和本地化有關,用於設定介面資訊的本地化。

   建立:iOS-Resource-Settings Bundle

3 設定項目種類

   Xcode Identifier-----記事本 Key  取消障眼法:右鍵-Show Raw Keys/Values

   1)文字欄位

       Type-PSTextFieldSpecifier Title-name 

   2)開關

      Type-PSToggleSwitchSpecifier Title-項目的標題

   3)滑塊

      Type-PSSliderSpecifier 

      將最大值圖片和最小值圖片添加到設定項目:將圖片複製到應用程式套件,格式是PNG。

   4)值列表

      為使用者提供多選一的列表

      Type-PSMultiValueSpecifier Title-項目標題  Titles字串數組-選項標題 Values-選項值

   5)子介面

      可以導航到下一級設定介面

      Type-PSChildPaneSpecifier File-設定子介面的.plist檔案名稱

4 讀取設定

  NSUserDefaults *deaults=[NSUserDefaults standardUserDefaults];

  取值方法:XXXForKey:根據鍵取出XXX值

 

- (IBAction)getData:(id)sender {        NSUserDefaults* defaults = [NSUserDefaults standardUserDefaults];    self.username.text = [defaults stringForKey:@"name_preference"];    self.password.text = [defaults stringForKey:@"password_preference"];        if ([defaults boolForKey:@"enabled_preference"]) {        self.clearCache.text = @"YES";    } else    {        self.clearCache.text = @"NO";    }        self.flowmeter.text = [NSString stringWithFormat:@"%.2fGB",[defaults doubleForKey:@"slider_preference"]];        self.serverName.text = [defaults stringForKey:@"multivaule_preference"];        if ([defaults boolForKey:@"sound_enabled_preference"]) {        self.notiSound.text = @"YES";    } else    {        self.notiSound.text = @"NO";    }            if ([defaults boolForKey:@"vibrate_enabled_preference"]) {        self.notiVibrate.text = @"YES";    } else    {        self.notiVibrate.text = @"NO";    }}

 

iOS 開發指南 第12章 應用程式設定

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.