问题
I am able to change the navbar color of the More navigationcontroller via:
stTabBarController.moreNavigationController.navigationBar.tintColor = [UIColor colorWithRed:(102.0/255.0) green:(20.0/255.0) blue:(11.0/255.0) alpha:1];
but when I click the Edit button, the Configure screen appears and the navbar color is the default blue. How can I change this color?
回答1:
Solved it:
#pragma mark UITabBarControllerDelegate
- (void)tabBarController:(UITabBarController *)controller willBeginCustomizingViewControllers:(NSArray *)viewControllers {
UIView *editViews = [controller.view.subviews objectAtIndex:1];
UINavigationBar *editModalNavBar = [editViews.subviews objectAtIndex:0];
editModalNavBar.tintColor = [UIColor colorWithRed:(102.0/255.0) green:(20.0/255.0) blue:(11.0/255.0) alpha:1];
}
回答2:
To anyone else with this question, in order for Sheehan Alam's solution to work, you need to make sure you set the tabBarController's delegate to self within the viewDidLoad method like so:
- (void)viewDidLoad {
...
self.delegate = self;
...
}
Then you need to make sure your tabBarController conforms to the UITabBarControllerDelegate protocol like so:
@interface TabBarController : UITabBarController <UITabBarControllerDelegate> {
...
}
Otherwise the method he's overriding won't be called.
回答3:
@Sheehan Alam solution did not work for me (working on iOS 8). Anyway I got 2/3 of the solution from his answers. I am posting this to improve the answer.
#prama mark - UITabBarControllerDelegate
- (void)tabBarController:(UITabBarController *)tabBarController willBeginCustomizingViewControllers:(NSArray *)viewControllers {
UIView *editViews = [tabBarController.view.subviews objectAtIndex:1];
for (UIView * view in [editViews subviews]) {
if ([view isKindOfClass:[UINavigationBar class]]) {
UINavigationBar *editNavBar = (UINavigationBar *)view;
editNavBar.barTintColor = [UIColor redColor];
}
}
}
来源:https://stackoverflow.com/questions/3301050/changing-the-navigationbar-color-on-the-edit-screen-of-the-more-section