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

后端 未结 16 1748
你的背包
你的背包 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:03

    I'm using following code (in C#) to change the color of the NavigationBar:

    NavigationController.NavigationBar.SetBackgroundImage (new UIImage (), UIBarMetrics.Default);
    NavigationController.NavigationBar.SetBackgroundImage (new UIImage (), UIBarMetrics.LandscapePhone);
    NavigationController.NavigationBar.BackgroundColor = UIColor.Green;
    

    The trick is that you need to get rid of the default background image and then the color will appear.

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

    The complete code with version checking.

     if (NSFoundationVersionNumber > NSFoundationVersionNumber_iOS_6_1) {
    
        // do stuff for iOS 7 and newer
        [self.navigationController.navigationBar setBarTintColor:[UIColor yellowColor]];
    }
    else {
    
        // do stuff for older versions than iOS 7
        [self.navigationController.navigationBar setTintColor:[UIColor yellowColor]];
    }
    
    0 讨论(0)
  • 2020-12-07 15:09

    // In ios 7 :-

    [self.navigationController.navigationBar setBarTintColor:[UIColor yellowColor]];
    

    // In ios 6 :-

    [self.navigationController.navigationBar setTintColor:[UIColor yellowColor]];
    
    0 讨论(0)
  • 2020-12-07 15:12

    Here is how to set it correctly for both iOS 6 and 7.

    + (void)fixNavBarColor:(UINavigationBar*)bar {
        if (iosVersion >= 7) {
            bar.barTintColor = [UIColor redColor];
            bar.translucent = NO;
        }else {
            bar.tintColor = [UIColor redColor];
            bar.opaque = YES;
        }
    }
    
    0 讨论(0)
  • 2020-12-07 15:12
        you can add bellow code in appdelegate.m .if your app is navigation based
    
        // for background color
       [nav.navigationBar setBarTintColor:[UIColor blueColor]];
    
        // for change navigation title and button color
        [[UINavigationBar appearance] setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[UIColor whiteColor],
        NSForegroundColorAttributeName,               
        [UIFont fontWithName:@"FontNAme" size:20],
        NSFontAttributeName, nil]];
        [[UINavigationBar appearance] setTintColor:[UIColor whiteColor]];
    
    0 讨论(0)
  • 2020-12-07 15:13

    Try the code below in the - (void)viewDidLoad of your ViewController.m

    [[[self navigationController] navigationBar] setTintColor:[UIColor yellowColor]];

    this did work for me in iOS 6.. Try it..

    0 讨论(0)
提交回复
热议问题