【问题标题】:Setting the same background colour on UIStatusBar as UINavigationBar在 UIStatusBar 上设置与 UINavigationBar 相同的背景颜色
【发布时间】:2014-01-25 11:15:13
【问题描述】:

我希望在我的应用程序中为UIStatusBar 设置背景颜色,我希望它与UINavigationBar 的背景颜色相匹配,与FacebookInstagram 应用程序相同。

我尝试将此函数添加到我的AppDelegate 中的didFinishLaunchingWithOptions 方法中:

-(void) setStatusBarColour{

    #define SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(v)  ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] != NSOrderedAscending)

    if (SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"7.0"))
    {
        UIView *view=[[UIView alloc] initWithFrame:CGRectMake(0, 0,self.window.rootViewController.view.frame.size.width, 20)];
        view.backgroundColor=[[UIColor lightGrayColor] colorWithAlphaComponent:0.6];
        [self.window.rootViewController.view addSubview:view];
    }
} 

它似乎不起作用。

有没有简单的方法可以做到这一点?

【问题讨论】:

    标签: ios objective-c ios7 uinavigationbar uistatusbar


    【解决方案1】:

    在 iOS 7 上,状态栏的背景颜色继承自导航栏的颜色。 所以你可以做这样的事情

    [[UINavigationBar appearance] setBarTintColor:[UIColor yellowColor]];

    并查看此链接:http://www.appcoda.com/customize-navigation-status-bar-ios-7/

    【讨论】:

    • 不错。我正在玩这个功能,并且还设置了导航栏的 backgroundColor 属性而不是栏的色调。但它现在有效。谢谢! :)
    【解决方案2】:

    您不需要为此编写额外的代码。一旦你改变了navigationBar的颜色,statusBar会自动为字体调整相同的颜色和色调。

    如何改变导航栏的颜色?

    关注this link

    这是 Facebook 栏颜色十六进制代码:#3B5998

    所以你的代码是:

    [[UINavigationBar appearance] setBarTintColor:[UIColor colorWithRed:59 green:89 blue:152 alpha:1]];
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-02-22
      • 1970-01-01
      • 2016-07-09
      • 2019-05-19
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多