iOS7 Global Tint not affecting UIToolbar - ios

I'm finding some situations where the Global Tint I have set in the MainStoryboard isn't propagating to some sub UIViews.
An example case is simply to start with a 'MasterDetail' template application and show the UIToolbar in the MasterViewController by adding:
-(void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
[self.navigationController setToolbarHidden:NO animated:YES];
}
Any items I add to the toolbar appear in the system default tint rather than my custom Global Tint.
Is anyone else having issues with this? Has anyone found a fix?
Thanks.

It doesn't seem to work on toolbars for some reason, I'm facing the same issue.
However, you can change the appearance (background not tini for some reason) of all uitoolbars from your AppDelegate, it works like charm.
Good luck, need any more help, let me know ;D

I've found a workaround.
Set the 'global tint' in code by setting the tint of the UIWindow and things work.
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
// Override point for customization after application launch.
[[[application windows] lastObject] setTintColor:[UIColor greenColor]];
return YES;
}
So despite the Apple documentation saying that the Global Tint setting is for the entire App, there's clearly an issue with that and you need to set it in code on the UIWindow.

Related

Using setNavigationBarHidden in viewWillAppear doesn't work

Assuming we are having three screens that are pushed after one another like this
A->B->C
And screen A is originally in a tabBar.
The navigation bar should be hidden in screen C and visible in all of the rest.To do this am doing the following
-(void) viewWillAppear:(BOOL)animated{
[super viewWillAppear:animated];
[self.navigationController setNavigationBarHidden: YES animated:NO];
}
The viewWillAppear gets called in all of the cases but hiding or showing the navigationBar is not necessarily gets reflected on the UI.
For example if used the back button the navigation bar appears in both A & B but if tapped the tabBarButton ,which causes the app to jump to screen A directly even from screen C, screen A will be missing the navigationBar.
I've check the self.navigatioController and it's initialized and has a value.
I've tried also to set the NavigationBarHidden property in the viewDidAppear but with no luck.
Any help on that issue? what may cause such a weird scenario?
Edit: Answer
I discovered the issue.
Screen C is a complex screen of a lot of containers.In one of the containers i was changing the navigationBar state and that affect everything else in the app and caused the weird behaviour and made me unable to control the state by myself.
Sorry for the trouble.
In both viewController A and viewController B, use this:
-(void) viewWillAppear:(BOOL)animated{
[super viewWillAppear:animated];
[self.navigationController setNavigationBarHidden: NO animated:NO];
}
In viewController c, use this(as mentioned in question):
-(void) viewWillAppear:(BOOL)animated{
[super viewWillAppear:animated];
[self.navigationController setNavigationBarHidden: YES animated:NO];
}
I discovered the issue.Screen C is a complex screen of a lot of containers.
in one of the containers i was changing the navigationBar state and that affect everything else in the app and caused the weird beahviour .
Try the following :-
[self.navigationController setNavigationBarHidden: YES animated:YES];
in place of :-
[self.navigationController setNavigationBarHidden: YES animated:NO];

Status bar becomes black

I have a status bar with style UIStatusBarStyleLightContent(white text). But when the Application is sent to background, in the task manager, the status bar is shown with black text and it stays black until the application is fully in foreground again (it is black through the whole go to front animation).
I observed this behavior only in iPhone 6 and iPhone 6+ (simulator and actual device). It shows up white (as expected) on iPhone 4s, 5 and 5s (tested on simulator)
I just found a solution. It is a bug which gets solved if the proper splash screens are defined.
Try following steps, should be working in iOS 8+ as well.
1) Add property View controller-based status bar appearance => NO in Info.plist.
2) Add following piece of code in AppDelegate.m
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
[UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleLightContent;
[self.window setBackgroundColor:[UIColor redColor]]; // Change color as per need.
return YES;
}
3) Override method in ViewController or you can consider overriding in ParentViewController of all ViewController if you have such Inheritance hierarchy. Otherwise you have to override this method in every ViewController.
- (UIStatusBarStyle) preferredStatusBarStyle {
return UIStatusBarStyleLightContent;
}

How to get notified when application goes background?

I need to protect my application from taking screenshot before going to background. I have added a black view in applicationDidEnterBackground:. But when I check background applications in iOS7 simulator it is not showing the black image instead it shows the application itself as shown in image. How can I solve this? If I get notified before app goes background this problem might be solved. Any help would be greatly appreciated.
The best way to achieve the functionality you want throughout your entire app is making your app navigate to an entirely black UIViewController. This so you cannot see anything when you long press on the homebutton and see the background applications.
These 2 functions will do the trick:
- (void) applicationDidEnterBackground:(UIApplication *)application
{
//navigate to the black view controller
BlackViewController *controller = [[BlackViewController alloc] init];
[yourNavigationController pushViewController:viewController animated:yourAnimationSettings];
[controller release];
}
- (void) applicationWillEnterForeground:(UIApplication *)application
{
//pop the black view controller so the user won't be bothered with it
if(/*Check if your BlackViewController is the top of your navigationController stack*/)
{
[yourNavigationController popViewControllerAnimated:yourAnimationSettings];
}
}
You'll get a callback in AppDelegate's applicationDidEnterBackground

uitextfield selected changes status bar color

I can't find what is wrong with UITextField (or UIStatusBar).
In my
- (BOOL)application:(UIApplication *)application
didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
I have:
[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent];
Also in my view controller I have this:
-(UIStatusBarStyle)preferredStatusBarStyle{
return UIStatusBarStyleLightContent;
}
The color of UIStatusBar is always white as I want it to be. But whenever I select UITextField, it's color changes to black. I don't want that, and I always want it to be white.
Strange but I can't find any similar issues on the net, so I'm hoping for your help. Any help is appreciated. Thanks in advance!
If you always want the UIStatusBar with whiteColor insert the line like you did in didFinishLaunching
[[UIApplication sharedApplication]
setStatusBarStyle:UIStatusBarStyleLightContent];
and than also set a value for the statusbar inside info.plist like this
You just need to set preferredStatusBarStyle inside a UIViewController if you want to change the color for a single controller.
Just Set the UIViewControllerBasedStatusBarAppearance to YES in the plist file
and also put in viewDidLoad method [self setNeedsStatusBarAppearanceUpdate]; may be its work for you.
Set the UIViewControllerBasedStatusBarAppearance to YES in the plist
In viewDidLoad do a [self setNeedsStatusBarAppearanceUpdate];
Add the following method:
-(UIStatusBarStyle)preferredStatusBarStyle{
return UIStatusBarStyleLightContent;
}
Okay this must not happen and so i don't see a need of setting the UIStatusBarStyle again and again... could you give a little more information about your UITextField?

iOS7 Navigation Bar + Status Bar Text Color

I have problems with colour of text in Status Bar. I want to make colour of text white, but keep black colour on modal views.
I have next configuration:
Storyboard with settings "Opens in 5.1" and "Project Deployment target 7.0" and "View as iOS7 and later"
UITabBarViewController
4 UINavigationControllers
Each navigation controller has custom subclass of UIViewController inside
Background colour of UINavigationBar set to dark via appearance.
View controller-based status bar appearance set to YES
My subclass of UITabBarViewController has next methods:
- (UIStatusBarStyle)preferredStatusBarStyle {
return UIStatusBarStyleLightContent;
}
- (void)viewDidLoad {
[super viewDidLoad];
[self setNeedsStatusBarAppearanceUpdate];
}
These methods are called after application started.
I also have same methods calls in my UIViewControllers subclasses:
- (UIStatusBarStyle)preferredStatusBarStyle {
return UIStatusBarStyleLightContent; // This method never called
}
- (void)viewDidLoad {
[super viewDidLoad];
[self setNeedsStatusBarAppearanceUpdate];
}
I also tried to change return value of -preferredStatusBarStyle to UIStatusBarStyleDefault (well, I know that it should paint text in black, but I tried anyway)
Same thing for setting Status Bar option to Light Content in Storyboard. Doesn't work too.
I know there are a lot of questions on SO similar to mine, but proposed solutions doesn't help in my situation.
My status bar still looks like this:
And I want to change its colour to white =/
This is a work around that I occasionally found right now after struggling with this issue for about 2 weeks.
// This is a workaround just enables white text colour in status bar in iOS7, iOS7.1
// Dont touch it until things break
// Despite this category says "draw white", colour automatically becomes black on white background w/o additional code
#interface UINavigationController (StatusBarStyle)
#end
#implementation UINavigationController (StatusBarStyle)
- (UIStatusBarStyle)preferredStatusBarStyle {
return UIStatusBarStyleLightContent;
}
#end
// Place at the bottom of your AppDelegate.m
// Magic!
I need to thank people who answered this question, but I already tried these solutions and they didn't help :( This category on UINavigationController just works.
First of all, you say that - (UIStatusBarStyle)preferredStatusBarStyle is never called in your UIViewController subclasses. It's normal. This method is called by your root view controller. In your case, it is the UITabBarViewController.
You also say that you've tried to set Status Bar option to Light Content in Storyboard. If you look closely, you should have done that in a section named Simulated metrics. So as the title suggest, modifications here are simulated...
I suggest you to try to add the key UIViewControllerBasedStatusBarAppearance in your Info.plist and to set it to YES.
You need to set this in your RootViewController :
[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent];

Resources