Changing the color of the UITabBar tints in the Advanced menu

I am trying to change the blue color using icons in more menus. I tried almost everything I found on Stack Overflow, but nothing worked. I tried this solution but doesn't work.

The only option I found to change the color was

[[UIView appearance] setTintColor:[UIColor redColor]];

      

but it changes all colors in the app.

tint color not changedtint color changed using UIView appearance tint color

The code is just a new project with a storyboard, so I just added views to the storyboard.
Thanks for the help.

Edit: After adding the code:

    UIImage *myImage = [[UIImage imageNamed:@"music.png"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
self.tabBarItem = [[UITabBarItem alloc] initWithTitle:@"New Title" image:myImage selectedImage:[UIImage imageNamed:@"music.png"]];

      

The image changes when the view is selected, but it is still blue.

+3


source to share


2 answers


To do what you need you have to use images by creating a UITabBarItem for each controller and adding the image and the selected image.

See Apple documentation about UITabBarItem

Otherwise here, from @Aaron Brager:



Change after full code selection First, your project has a lot of errors, assets should be in xcassets folder, meaning didload writes your code after "super viewDidLoad" etc.

About your problem, in your viewDidLoad method in FirstViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    // Your code start here, not before the super
    [[UITabBar appearance] setTintColor:[UIColor redColor]];

    // Get table view of more new viewController
    UITableView *view =(UITableView*)self.tabBarController.moreNavigationController.topViewController.view;

    view.tintColor = [UIColor redColor]; // Change the image color

    if ([[view subviews] count]) {
        for (UITableViewCell *cell in [view visibleCells]) {
            cell.textLabel.textColor = [UIColor redColor]; // Change the text color

        }
    }
}

      

+7


source


This is the Swift version of Louis .

Please be aware that this version changes the hue color as the original answer changed the text color a lot. To change it correctly, you will have to override moreNavigationController

its function as well cellForRowAt

.



tabBarController?.tabBar.tintColor = .red

if let moreTableView = tabBarController?.moreNavigationController.topViewController?.view as? UITableView {
    moreTableView.tintColor = .red
}

      

0


source







All Articles