简体   繁体   中英

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:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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