Subclass / extension tabBarController and implement these methods (I know this is obj-c, but it should work as directly translated into swift):
#import "const.h" #import "MainTabBarController.h" @interface MainTabBarController () @end @implementation MainTabBarController - (NSArray*)tabTitles { return @[@"Connection", @"Details", [[NSUserDefaults standardUserDefaults] objectForKey:@"LastProfileResponse"] ? @"Profile" : @"Login", @"Settings"]; } - (void)viewDidLoad { [super viewDidLoad]; NSArray *imageNames = @[@"connection_tab_", @"details_tab_", @"profile_tab_", @"settings_tab_" ]; for (int i = 0; i < self.tabBar.items.count; ++i) { ((UITabBarItem*)self.tabBar.items[i]).title = self.tabTitles[i]; ((UITabBarItem*)self.tabBar.items[i]).selectedImage = [UIImage imageNamed:[imageNames[i] stringByAppendingString:@"on"]]; ((UITabBarItem*)self.tabBar.items[i]).image = [[UIImage imageNamed:[imageNames[i] stringByAppendingString:@"off"]] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]; } self.tabBar.translucent = false; self.tabBar.barTintColor = SLATE_GREEN; self.tabBar.tintColor = YELLOW; self.delegate = self; [[UITabBarItem appearance] setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:WHITE, NSForegroundColorAttributeName, TAB_FONT, NSFontAttributeName, nil] forState:UIControlStateNormal]; [[UITabBarItem appearance] setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:YELLOW, NSForegroundColorAttributeName, nil] forState:UIControlStateSelected]; }
source share