SetFinishedSelectedImage: withFinishedUnselectedImage: + Storyboards

I have an interface fully laid out using a storyboard (including the UITabBarController and all relevant views).

Now it's time to customize the tab bar. Since I have icons that are already set to the correct color, I cannot use [[UITabBar appearance] setTintColor:](it just continues to look wrong).

Turns out I should use setFinishedSelectedImage:withFinishedUnselectedImage:for a specific UITabBarItem.

Can I use this method from AppDelegate (where the rest of my global setup is done)? How does AppDelegate know which UITabBar is targeted?

If instead I have to configure each UITabBarItem from each UIViewController, how can I refer to a UITabBar (or "root view controller"?) And then to a specific element from a UIViewController?

Any help would be greatly appreciated. Thank you

+3
source share
2 answers

In viewDidLoadyour instances UIViewControlleryou can do

[self.tabBarItem setFinishedSelectedImage: withFinishedUnselectedImage:]
+2
source

try it

- (id)initWithCoder:(NSCoder *)aDecoder
{
    self = [super initWithCoder:aDecoder];

    if (self) {
        [self.tabBarItem setFinishedSelectedImage:[UIImage imageNamed:@"t1s"] withFinishedUnselectedImage:[UIImage imageNamed:@"t1"]];
        [self.tabBarItem setTitle:@"Title"];
    }

    return self;
}

Also, remove the image in the scoreboard item from the storyboard view.

+1
source

All Articles