StatusBar 狀態欄顏色

項目中有時候須要改變 狀態欄 的顏色 、隱藏、顯示等網絡

 

一、改變顏色:app

黑色(默認),白色spa

UIStatusBarStyleDefault         // Dark content, for use on light backgroundscode

UIStatusBarStyleLightContent    // Light content, for use on dark backgroundsit

 

實例io

    [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent];
    [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent animated:YES];
    //調用上述方法後須要及時刷新
    [self setNeedsStatusBarAppearanceUpdate];
    //若上述刷新沒有起到做用 須要改變 info.plist 文件View controller-based status bar appearance 值爲NO;

二、是否隱藏:sed

[UIApplication sharedApplication].statusBarHidden = NO;

 

三、詳解date

狀態欄拆分:方法

如圖:狀態欄分爲 前置部分後置部分im

前置部分:網絡狀態、時間、電量

後置部分:背景顏色(此圖爲乳白)

 

改變狀態欄的方式:

①代碼; ②plist 文件

通常在plist文件中設置是 全局設置,項目中不須要再次設置;而代碼設置則要靈活的多,多用於須要常常改變狀態欄的app中

plist 文件:

在plist中增長一項: Status bar style,並設置想要的值。

 

代碼:

//顏色
self.navigationController.navigationBar.barTintColor = [UIColor yellowColor];

 

其餘方法:

設置一個view,添加到navigationbar上

    UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, -20)];
    view.backgroundColor = [UIColor redColor];
    [self.navigationController.navigationBar addSubview:view];
相關文章
相關標籤/搜索