4

I'm trying to change the blue colour from icons in the more menu. I tried almost everything I found on Stack Overflow, but nothing worked. I tried this solution, but is not working.

The only option I found to change the colour was

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

but it changes all colours in the app.

tint color not changed tint colour changed using UIView appearance tint color

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

Edit: After I added 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 is changed when the view is selected, but it's still blue.

Tamás Sengel
  • 55,884
  • 29
  • 169
  • 223
varu
  • 339
  • 4
  • 16

3 Answers3

7

To do what you need, you should use images by creating UITabBarItem for each controller and add an image and a selected image.

See Apple Documentation about UITabBarItem

Otherwise looks here, from @Aaron Brager :

Edit after seing the full code First there is many mistakes in your project, assets should be in xcassets folder, in view didload write your code after the 'super viewDidLoad]', etc.

About your problem, in your viewDidLoad method in the 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

        }
    }
}
Community
  • 1
  • 1
Ludovic
  • 1,992
  • 1
  • 21
  • 44
  • Thanks for the reply, I tried the code from suggestions but still doesn't work. I guess I'm doing something wrong. I attached the full code if you can take a look. – varu Sep 29 '14 at 19:56
  • @varu I just updated my answer. I didn't understand you were using Storyboard! – Ludovic Sep 29 '14 at 20:45
  • I had this problem with tint color on a bigger project what was begun in 2010 and I had to fix the issue with the icons. I created a new project just for StackOverflow. Thank you very much for helping me. I really appreciate your help. I still have a lot to learn :) – varu Sep 30 '14 at 06:04
2

This is the Swift version of Ludovic's answer.

Keep in mind that this version only changes the tint color, since the original answer did the text color change in a very hacky way. For changing it properly, you'd have to override moreNavigationController and its cellForRowAt function.

tabBarController?.tabBar.tintColor = .red

if let moreTableView = tabBarController?.moreNavigationController.topViewController?.view as? UITableView {
    moreTableView.tintColor = .red
}
Tamás Sengel
  • 55,884
  • 29
  • 169
  • 223
0

to change color of this button

    moreNavigationController.navigationBar.tintColor = .white

enter image description here

coders
  • 2,287
  • 1
  • 12
  • 20