如何更改状态栏的背景颜色而不是导航栏的背景颜色?

时间:2015-12-24 06:19:35

标签: ios objective-c uinavigationcontroller uinavigationbar statusbar

RootVc: enter image description here

PushVc: enter image description here

如何实现这种效果?

如何更改状态栏的背景颜色而不是导航栏的背景颜色?

3 个答案:

答案 0 :(得分:1)

将此方法添加到每个viewcontroller,或(从类别方法调用)

-(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;
}

冷..

答案 1 :(得分:0)

设置 $(".deleteUserIncomesJson").click(function(){ $.ajax({ url: "deleteUserIncomesJson", data: {incomeID:incomeID}, type: "POST", success: function(result) { alert('record Deleted'); //code to repopulate the entire table } }); }); View controller-based status bar appearance。在您的项目info.plist.and中从项目设置您可以根据您的要求更改状态栏bG颜色

我有一个建议请更改Windows BG颜色并设置状态栏NO 在appdelegate.m中添加以下代码:

UIStatusBarStyleBlackTranslucent

答案 2 :(得分:0)

以下是我用来更改状态栏颜色或背景的代码。

     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];
*/        
}

如果我不工作,试试这个,请告诉我。