簡體   English   中英

如何更改狀態欄的背景顏色而不更改導航欄的背景顏色?

[英]How to change background color of status bar but not that of navigation bar?

RootVc: 在此處輸入圖片說明

PushVc: 在此處輸入圖片說明

如何實現這種效果?

如何更改狀態欄的背景顏色而不更改導航欄的背景顏色?

將此方法添加到您的每個viewcontroller中,或(從category方法中調用)

-(void)status_bar_color
{
      if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7.0)
      {
            UIView *addStatusBar = [[UIView alloc] init];
            CGSize result = [[UIScreen mainScreen] bounds].size;
            if(result.height >750)
            {
                  addStatusBar.frame = CGRectMake(0, 0, 800, 23);
            }
            else if(result.height >550)//IPod
            {
                  addStatusBar.frame = CGRectMake(0, 0, 320, 23);
            }
            else
            {
                  addStatusBar.frame = CGRectMake(0, 0, 320, 23);
            }

            addStatusBar.backgroundColor=[UIColor blackColor];
            [self.view addSubview:addStatusBar];
      }
}

對於狀態欄的淺色內容,也可以使用此方法,

-(UIStatusBarStyle)preferredStatusBarStyle
{
      return UIStatusBarStyleLightContent;
}

涼..

設置View controller-based status bar appearanceNO 在您的項目info.plist。和項目設置中,您可以根據需要更改狀態欄bG顏色

我有一個建議,請更改Windows BG顏色並設置狀態欄UIStatusBarStyleBlackTranslucent在appdelegate.m中添加以下代碼:

self.window.backgroundColor = [UIColor <yourColor>];
[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleBlackTranslucent];

這是我用來更改狀態欄顏色或背景的代碼。

     if (SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"7.0"))
        {
            UIView *view=[[UIView alloc] initWithFrame:CGRectMake(0, 0,[UIScreen mainScreen].bounds.size.width, 20)];
     view.backgroundColor=[UIColor YourColorName];

If you wanted to add image you can use the line given below.  
/*
            view.backgroundColor=[UIColor colorWithPatternImage:[UIImage imageNamed:@"loginbackground.png"]];
            [self.view addSubview:view];
*/        
}

如果我不工作,請嘗試此操作,請讓我知道。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM