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

标签 ios objective-c uinavigationcontroller uinavigationbar statusbar

根目录: enter image description here

推Vc: enter image description here

如何实现这个效果?

如何改变状态栏的背景色而不改变导航栏的背景色?

最佳答案

将此方法添加到您的每个 View Controller ,或(从类别方法中调用它)

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

statusbar的浅色内容,也用这个方法,

-(UIStatusBarStyle)preferredStatusBarStyle
{
      return UIStatusBarStyleLightContent;
}

很酷..

关于ios - 如何更改状态栏的背景颜色而不是导航栏的背景颜色?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34448225/

相关文章:

ios - 有没有办法阻止 UICollectionView 重复使用单元格?

ios - 让 UITableView 的标题部分中的 UIImageView 与内容单元格重叠

iphone - iOS 状态栏会自行更改颜色以匹配导航栏

ios - uinavigationcontroller - 显示堆栈

ios - 如何在不阻塞主线程的情况下等待网络调用在 iOS 上返回数据?

ios - 通缉解释 : Concept of passing data between UIViewController and UIView

ios - 使用 kCAMediaTimingFunctionEaseIn 有问题吗?

iphone - 从 UIImagePicker 中删除相机控件 - 如何放大到全屏 - iPhone/iPad

ios - 在 Objective-C 中定义一个位置矩形

iOS:如何检测弹出或关闭后是否出现viewcontroller