Reputation: 4425
I am having a weird problem. Whenever my application launches, I do the following in the AppDelegate:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
// Override point for customization after application launch.
[[UINavigationBar appearance] setBarTintColor:[UIColor whiteColor]];
[[UINavigationBar appearance] setTintColor:[UIColor mainLightBlue]];
[[UITabBar appearance] setTintColor:[UIColor mainLightBlue]];
[IJContext setDefaultContext:[[IJContext alloc] init]];
RKLogConfigureFromEnvironment();
return YES;
}
Then, if my user successfully logs in, I do the following in the AppDelegate:
-(void)presentNewsFeed
{
RKLogConfigureByName("RestKit/Network", RKLogLevelDebug);
UIViewController *newTopViewController = [[UIStoryboard storyboardWithName:@"MainiPadStoryboard" bundle:nil] instantiateViewControllerWithIdentifier:@"GlobalInitialSliding"];
[_window setRootViewController:newTopViewController];
}
At this point, the setTintColor is working fine. Now, whenever a user logs out, I call:
- (void)presentLoginScreen
{
UIViewController *newTopViewController = [[UIStoryboard storyboardWithName:@"MainiPadStoryboard" bundle:nil] instantiateViewControllerWithIdentifier:@"Login"];
[_window setRootViewController:newTopViewController];
}
Which is again located in the AppDelegate. If the logs back in, I call once again presentNewsFeed
. However, on that second time, the setTintColor is no longer working, and all my tabs do not actually have a tintColor whenever their are selected. So my users can't actually know which tab is selected. Any ideas as to why?
Upvotes: 2
Views: 683
Reputation: 47099
From your question:
Then, if my user successfully logs in, I do the following in the AppDelegate
:
-(void)presentNewsFeed
{ ... }
It means your first screen is Login Screen then why do not you set setRootViewController
as yourLoginScreenViewController? In your code, You will be also receive a warning such like Applications are expected to have a root view controller at the end of application launch
? Because when you will do launch you app at that time your window has not rootViewController so.
And If you follow my suggestion then it is very easy for you to get LoginScreen whenever you LoggedOut, By using following code:
[self.navigationController popToRootViewControllerAnimated:YES];
Because here your RootViewController
is your LoginScreen so you directly reach at your RootViewController
and also not worry about re-creation of RootViewController
.
Upvotes: 1
Reputation: 887
You can set an image (1px for width and 49 px for height
) and save it, for example: tabBg.png
, and then you replace:
[[UITabBar appearance] setTintColor:[UIColor mainLightBlue]];
by this:
UIImage *tabBarBackground = [UIImage imageNamed:@"tabBg.png"];
[[UITabBar appearance] setBackgroundImage:tabBarBackground];
I hope this helps you.
Upvotes: 0
Reputation: 4425
I had another declaration of the tintColor
in a viewController
and it was messing with the one in the appDelegate
!
Thanks
Upvotes: 2
Reputation: 1097
Try this code for setting flat red color for tabbar
[[UITabBar appearance] setBackgroundColor:[UIColor redColor]];
for setting image Try this
UIImage *tabBackground = [[UIImage imageNamed:@"tab_bg"]
resizableImageWithCapInsets:UIEdgeInsetsMake(0, 0, 0, 0)];
[[UITabBar appearance] setBackgroundImage:tabBackground];
[[UITabBar appearance] setSelectionIndicatorImage:
[UIImage imageNamed:@"tab_select_indicator"]];
Upvotes: 1