Status bar - iOS之狀態列

來源:互聯網
上載者:User

標籤:control   set   navig   子類   statusbar   app   ase   pre   全域   

(一)設定狀態列顯示和隱藏1、通過 Info.plist 檔案增加欄位,控制狀態列全域顯示和隱藏
  • 在 Info.plist 檔案中增加欄位 Status bar is initially hidden  設定為 YES ,那麼 app 在 LaunchScreen 頁面隱藏狀態列
  • 在 Info.plist 檔案增加欄位 View controller-based status bar appearance 設定為 YES,那麼app預設所有頁面都會顯示狀態列
2、通過代碼,控制狀態列全域顯示和隱藏
  • 在 Info.plist 檔案 View controller-based status bar appearance 設定為 NO時,代碼設定狀態列才會起作用。
  • 在 AppDelegate.m 中添加代碼 [[UIApplication sharedApplication] setStatusBarHidden:NO];
3、通過代碼,控制狀態列局部顯示和隱藏
  • 在 Info.plist 檔案 View controller-based status bar appearance 設定為 YES
  • 在需要隱藏狀態列的VC中重寫寫法 - (BOOL)prefersStatusBarHidden { return YES;},返回YES
  (二)設定狀態列顏色1、設定狀態列文字部分的顏色
  • 全域文字顏色:在 Info.plist 增加key值 Status bar style,value可以設定 UIStatusBarStyleDefault (預設黑色)和 UIStatusBarStyleLightContent (白色)。
  • 全域文字顏色:在 Info.plist 檔案 View controller-based status bar appearance 設定為 NO時,且在 AppDelegate.m 中添加2行代碼 [[UIApplication sharedApplication] setStatusBarHidden:NO];   [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent]; 即可!注意:此處 Info.plist中添加的key值對應的value必須為NO,若為YES,則代碼不起作用。
  • 局部文字顏色:此處分2種不同情況
           首先設定,在 Info.plist 檔案 View controller-based status bar appearance 設定為 YES           a. ViewController 不嵌套在 UINavigationController 中,需要設定以下                重寫 UIViewController 方法 - (UIStatusBarStyle)preferredStatusBarStyle { return UIStatusBarStyleDefault; }            b. ViewController 為 UINavigationController 的rootVC,需要設定以下                繼承 UINavigationController 寫一個子類,然後重寫方法:                - (UIStatusBarStyle)preferredStatusBarStyle {                        return self.topViewController.preferredStatusBarStyle;                } 關於以上狀態列的顯示和隱藏、文字或背景顏色均為親測,若存在問題,麻煩留言@我!

Status bar - iOS之狀態列

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.