简体   繁体   English

有没有办法在应用程序中普遍设置背景颜色或导航栏?

[英]Is there a way to set the background color or navigation bar universally across an app?

Right now, I have to do something like the below before pushing a view every time 现在,我必须在每次推送视图之前执行类似下面的操作

    _homeNavigationController.navigationBar.barStyle = UIBarStyleBlack;
    _homeNavigationController.navigationBar.tintColor = nil;     

And I want to set the color to different one using an patterned image. 我想用图案图像将颜色设置为不同的颜色。

So is there a simple way to do it? 那么有一个简单的方法吗?

If you want to use custom tint colors (other than the built-in constants), use this code: 如果要使用自定义色调颜色(内置常量除外),请使用以下代码:

Define these somewhere globally. 在全球范围内定义这些。

#define RGBCOLOR(r,g,b)         [UIColor colorWithRed:(r)/255.0f green:(g)/255.0f blue:(b)/255.0f alpha:1]
#define COLOR_NAVBAR_TINT           RGBCOLOR(82, 154, 217)
#define COLOR_TOOLBAR_TINT          RGBCOLOR(82, 154, 217)

Add this to your AppDelegate.m, and then invoke it during your app's initialization: 将其添加到AppDelegate.m,然后在应用程序初始化期间调用它:

- (void)initializeGlobalTheme {
    [[UINavigationBar appearance] setTintColor:COLOR_NAVBAR_TINT];
    [[UIToolbar appearance] setTintColor:COLOR_TOOLBAR_TINT];
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM