ios7中UIViewControllerBasedStatusBarAppearance作用詳解
ios7中UIViewControllerBasedStatusBarAppearance詳解
在作iOS7的適配時,很多文章都會提到UIViewControllerBasedStatusBarAppearance。便一直不是太明白其實際作用,使用時發(fā)現UIViewControllerBasedStatusBarAppearance的實際作用如下:
這個屬性只影響如何設置status bar上字體的顏色是暗色(黑色)還是亮色(白色),對status bar的背景色無影響。status bar的背景色在iOS7上永遠是透明的。
apple官方對UIViewControllerBasedStatusBarAppearance得說明:
UIViewControllerBasedStatusBarAppearance (Boolean - iOS) specifies whether the status bar appearance is based on the style preferred by the view controller that is currently under the status bar. When this key is not present or its value is set to YES, the view controller determines the status bar style. When the key is set to NO, view controllers (or the app) must each set the status bar style explicitly using the UIApplication object.
即:UIViewControllerBasedStatusBarAppearance(一個Boolean值)指定狀態(tài)欄的外觀是否是基于當前視圖控制器給狀態(tài)欄指定的首選風格。當這個鍵不存在,或者它的值設置為YES時(也就是說這個key的默認value為yes),視圖控制器決定了狀態(tài)欄的風格。當按鍵被設置為NO,視圖控制器(或應用程序)都必須通過UIApplication對象(即UIApplication的setStatusBarStyle方法)顯示的設置狀態(tài)欄風格。
通過apple的官方文檔不難看出,在ios7上,設置狀態(tài)欄風格(暗色或者亮色)的方法無非就兩種,第一種是在controller中通過回調方法preferredStatusBarStyle返回狀態(tài)欄的風格,第二種是通過UIApplication對象的setStatusBarStyle設置, UIViewControllerBasedStatusBarAppearance實際上是指定了是否優(yōu)先使用第一種方法(這也就不難理解為什么這個key值叫做UIViewControlle “based”)。
所以當plist中沒有UIViewControllerBasedStatusBarAppearance這個key,或者存在這個key,并且value為YES時,
viewController的preferredStatusBarStyle方法對狀態(tài)欄的設置生效;
當UIViewControllerBasedStatusBarAppearance對應的value為NO時,
[UIApplication sharedApplication] 通過方法setStatusBarStyle對狀態(tài)欄的設置生效。
隱藏狀態(tài)欄
有時候我們需要隱藏狀態(tài)欄,那么此時我們在view controller中override方法prefersStatusBarHidden:即可,如下代碼所示:
- (BOOL)prefersStatusBarHidden
{
return YES;
}
感謝閱讀,希望能幫助到大家,謝謝大家對本站的支持!
相關文章
ios 不支持 iframe 的完美解決方法(兼容iOS&安卓)
下面小編就為大家?guī)硪黄猧os 不支持 iframe 的完美解決方法(兼容iOS&安卓)。小編覺得挺不錯的,現在就分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2017-07-07
淺析iOS中的淺拷貝和深拷貝(copy和mutableCopy)
ios提供了copy和mutablecopy方法,顧名思義,copy就是復制了一個imutable的對象,而mutablecopy就是復制了一個mutable的對象。本文給大家介紹iOS中的淺拷貝和深拷貝(copy和mutableCopy) ,感興趣的朋友一起看看吧2016-04-04
Objective-C處理空字符串和頁面?zhèn)髦导白远x拷貝
這篇文章主要介紹了Objective-C處理空字符串和頁面?zhèn)髦导白远x拷貝的相關方法,在iOS應用項目開發(fā)中經常會用到,需要的朋友可以參考下2016-01-01

