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

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

    One more thing, if you want to change the navigation bg color in UIPopover you need to set barStyle to UIBarStyleBlack

    if([UINavigationBar instancesRespondToSelector:@selector(barTintColor)]){ //iOS7
        navigationController.navigationBar.barStyle = UIBarStyleBlack;
        navigationController.navigationBar.barTintColor = [UIColor redColor];
    }
    
    0 讨论(0)
  • 2020-12-07 15:27

    The behavior of tintColor for bars has changed on iOS 7.0. It no longer affects the bar's background and behaves as described for the tintColor property added to UIView. To tint the bar's background, please use -barTintColor.

    navController.navigationBar.barTintColor = [UIColor navigationColor];

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

    Insert the below code in didFinishLaunchingWithOptions() in AppDelegate.m

    [[UINavigationBar appearance] setBarTintColor:[UIColor
        colorWithRed:26.0/255.0 green:184.0/255.0 blue:110.0/255.0 alpha:1.0]];
    
    0 讨论(0)
  • 2020-12-07 15:28

    The background color property is ignored on a UINavigationBar, so if you want to adjust the look and feel you either have to use the tintColor or call some of the other methods listed under "Customizing the Bar Appearance" of the UINavigationBar class reference (like setBackgroundImage:forBarMetrics:).

    Be aware that the tintColor property works differently in iOS 7, so if you want a consistent look between iOS 7 and prior version using a background image might be your best bet. It's also worth mentioning that you can't configure the background image in the Storyboard, you'll have to create an IBOutlet to your UINavigationBar and change it in viewDidLoad or some other appropriate place.

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