欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

ios7中UIViewControllerBasedStatusBarAppearance作用詳解

 更新時間:2016年11月10日 17:15:20   作者:skyYangpan  
這篇文章主要介紹了 ios7中UIViewControllerBasedStatusBarAppearance作用詳解的相關(guān)資料,需要的朋友可以參考下

  ios7中UIViewControllerBasedStatusBarAppearance詳解

在作iOS7的適配時,很多文章都會提到UIViewControllerBasedStatusBarAppearance。便一直不是太明白其實(shí)際作用,使用時發(fā)現(xiàn)UIViewControllerBasedStatusBarAppearance的實(shí)際作用如下:      

這個屬性只影響如何設(shè)置status bar上字體的顏色是暗色(黑色)還是亮色(白色),對status bar的背景色無影響。status bar的背景色在iOS7上永遠(yuǎn)是透明的。

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)欄的外觀是否是基于當(dāng)前視圖控制器給狀態(tài)欄指定的首選風(fēng)格。當(dāng)這個鍵不存在,或者它的值設(shè)置為YES時(也就是說這個key的默認(rèn)value為yes),視圖控制器決定了狀態(tài)欄的風(fēng)格。當(dāng)按鍵被設(shè)置為NO,視圖控制器(或應(yīng)用程序)都必須通過UIApplication對象(即UIApplication的setStatusBarStyle方法)顯示的設(shè)置狀態(tài)欄風(fēng)格。

通過apple的官方文檔不難看出,在ios7上,設(shè)置狀態(tài)欄風(fēng)格(暗色或者亮色)的方法無非就兩種,第一種是在controller中通過回調(diào)方法preferredStatusBarStyle返回狀態(tài)欄的風(fēng)格,第二種是通過UIApplication對象的setStatusBarStyle設(shè)置, UIViewControllerBasedStatusBarAppearance實(shí)際上是指定了是否優(yōu)先使用第一種方法(這也就不難理解為什么這個key值叫做UIViewControlle “based”)。

所以當(dāng)plist中沒有UIViewControllerBasedStatusBarAppearance這個key,或者存在這個key,并且value為YES時,
viewController的preferredStatusBarStyle方法對狀態(tài)欄的設(shè)置生效;

當(dāng)UIViewControllerBasedStatusBarAppearance對應(yīng)的value為NO時,
[UIApplication sharedApplication] 通過方法setStatusBarStyle對狀態(tài)欄的設(shè)置生效。

隱藏狀態(tài)欄

有時候我們需要隱藏狀態(tài)欄,那么此時我們在view controller中override方法prefersStatusBarHidden:即可,如下代碼所示:

- (BOOL)prefersStatusBarHidden 
{ 
  return YES; 
} 

 感謝閱讀,希望能幫助到大家,謝謝大家對本站的支持!

相關(guān)文章

最新評論