E. Rivera
E. Rivera

Reputation: 10938

How to set the "more" tab bar's edit view's navigation bar black?

I am trying to set all my tab bar's navigation bars UIBarStyleBlack.

I could also achieve this for the "more" tab bar with this:

tabBarController.moreNavigationController.navigationBar.barStyle = UIBarStyleBlack;

The problem is that when you click its top Edit button to customize the tabs it presents a new modal controller with a standard blue navigation bar, and I can't manage to set it UIBarStyleBlack.

Upvotes: 1

Views: 2013

Answers (3)

Arijan
Arijan

Reputation: 326

Swift - customizing Tabbar -> More menu -> Edit view (navigation bar and content view).

override func tabBar(_ tabBar: UITabBar, willBeginCustomizing items: [UITabBarItem]) {
    for (index, subView) in view.subviews.enumerated() {
        subView.backgroundColor = UIColor.black
        if index == 1 {
            subView.tintColor = UIColor.green
            for customSubView in subView.subviews {
                if let navBar = customSubView as? UINavigationBar {
                    navBar.isTranslucent = false
                    navBar.barTintColor = UIColor.black
                    navBar.tintColor = .white
                }
            }
        }
    }
}

This is what worked for me.

Upvotes: 2

gklka
gklka

Reputation: 2574

Sublcass UITabBarController and overwrite these methods:

- (void)tabBar:(UITabBar *)tabBar willEndCustomizingItems:(NSArray<UITabBarItem *> *)items changed:(BOOL)changed {
    self.moreNavigationController.navigationBar.barStyle = UIBarStyleBlack;
}

- (void)tabBar:(UITabBar *)tabBar didBeginCustomizingItems:(NSArray<UITabBarItem *> *)items {
    self.moreNavigationController.navigationBar.barStyle = UIBarStyleDefault;
}

Upvotes: 0

E. Rivera
E. Rivera

Reputation: 10938

The link has a slightly hackie solution that involves listening to when the modal view will appear.

Colouring fun with moreNavigationController

Until iOS5+ enables us to do it in a cleaner way.

Upvotes: 3

Related Questions