How to change navigation bar color in iOS 7 or 6?

后端 未结 16 1749
你的背包
你的背包 2020-12-07 14:33

I want to change the color of the navigation bar color, but I\'m not sure whether or not I should change the tint or the background. I know iOS 7 is going for a more flat de

相关标签:
16条回答
  • 2020-12-07 15:15

    Based on posted answered, this worked for me:

    /* check for iOS 6 or 7 */
    if ([[self navigationController].navigationBar respondsToSelector:@selector(setBarTintColor:)]) {
        [[self navigationController].navigationBar setBarTintColor:[UIColor whiteColor]];
    
    } else {
        /* Set background and foreground */
        [[self navigationController].navigationBar setTintColor:[UIColor whiteColor]];
        [self navigationController].navigationBar.titleTextAttributes = [[NSDictionary alloc] initWithObjectsAndKeys:[UIColor blackColor],UITextAttributeTextColor,nil];
    }
    
    0 讨论(0)
  • 2020-12-07 15:16

    If you want to have a solid color for your navigation bar in iOS 6 similar to iOS 7 use this:

    [[UINavigationBar appearance] setBackgroundImage:[[UIImage alloc] init] forBarMetrics:UIBarMetricsDefault];
    [[UINavigationBar appearance] setBackgroundColor:[UIColor greenColor]];
    

    in iOS 7 use the barTintColor like this:

    navigationController.navigationBar.barTintColor = [UIColor greenColor];
    

    or

     [[UINavigationBar appearance] setBarTintColor:[UIColor greenColor]];
    
    0 讨论(0)
  • 2020-12-07 15:17

    If you want to change a color of a navigation bar, use barTintColor property of it. In addition, if you set any color to tintColor of it, that affects to the navigation bar's item like a button.

    FYI, you want to keep iOS 6 style bar, make a background image looks like previous style and set it.

    For more detail, you can get more information from the following link:

    https://developer.apple.com/library/ios/documentation/userexperience/conceptual/TransitionGuide/AppearanceCustomization.html

    0 讨论(0)
  • 2020-12-07 15:18

    In iOS7, if your navigation controller is contained in tab bar, splitview or some other container, then for globally changing navigationbar appearance use following method ::

    [[UINavigationBar appearanceWhenContainedIn:[UITabBarController class],nil] setBarTintColor:[UIColor blueColor]];
    
    0 讨论(0)
  • 2020-12-07 15:19

    I'm not sure about changing the tint vs the background color but this is how you change the tint color of the Navigation Bar:

    Try this code..

    [navigationController.navigationBar setTintColor:[UIColor redColor]; //Red as an example.

    0 讨论(0)
  • 2020-12-07 15:23

    You can check iOS Version and simply set the tint color of Navigation bar.

    if (SYSTEM_VERSION_LESS_THAN(@"7.0")) {
        self.navigationController.navigationBar.tintColor = [UIColor colorWithRed:0.9529 green:0.4392 blue:0.3333 alpha:1.0];
    }else{
    
        self.navigationController.navigationBar.barTintColor = [UIColor colorWithRed:0.9529 green:0.4392 blue:0.3333 alpha:1.0];
        self.navigationItem.leftBarButtonItem.tintColor = [UIColor whiteColor];
        [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent];
    }
    
    0 讨论(0)
提交回复
热议问题