国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 系統 > iOS > 正文

ios7中UIViewControllerBasedStatusBarAppearance作用詳解

2019-10-21 18:50:48
字體:
來源:轉載
供稿:網友

  ios7中UIViewControllerBasedStatusBarAppearance詳解

在作iOS7的適配時,很多文章都會提到UIViewControllerBasedStatusBarAppearance。便一直不是太明白其實際作用,使用時發現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值)指定狀態欄的外觀是否是基于當前視圖控制器給狀態欄指定的首選風格。當這個鍵不存在,或者它的值設置為YES時(也就是說這個key的默認value為yes),視圖控制器決定了狀態欄的風格。當按鍵被設置為NO,視圖控制器(或應用程序)都必須通過UIApplication對象(即UIApplication的setStatusBarStyle方法)顯示的設置狀態欄風格。

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

所以當plist中沒有UIViewControllerBasedStatusBarAppearance這個key,或者存在這個key,并且value為YES時,
viewController的preferredStatusBarStyle方法對狀態欄的設置生效;

當UIViewControllerBasedStatusBarAppearance對應的value為NO時,
[UIApplication sharedApplication] 通過方法setStatusBarStyle對狀態欄的設置生效。

隱藏狀態欄

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

- (BOOL)prefersStatusBarHidden {   return YES; } 

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


注:相關教程知識閱讀請移步到IOS開發頻道。
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 克山县| 台北县| 洛阳市| 巨鹿县| 龙口市| 临桂县| 车致| 东辽县| 长宁区| 常熟市| 沈阳市| 张北县| 灵石县| 和龙市| 镇江市| 株洲县| 临澧县| 汤原县| 岗巴县| 雅安市| 内黄县| 罗田县| 浦县| 滨州市| 贺兰县| 建阳市| 舒城县| 乐都县| 巴林左旗| 涪陵区| 名山县| 永城市| 枣庄市| 麻阳| 基隆市| 睢宁县| 九寨沟县| 汾阳市| 越西县| 孝昌县| 治多县|