StatusBar colour never changes when using NavigationBars on iOS 7 - objective-c

I am trying to change the app StatusBar colour and it works ONLY when my XIB has no navigationBars. To do so, I added the following function to my source file:
-(UIStatusBarStyle)preferredStatusBarStyle{
return UIStatusBarStyleLightContent;
}
But when I call [self.navigationController setNavigationBarHidden:NO animated:NO]; the status bar goes back to the default style.
It leads me to believe that the navigation bar should set the statusBar colour for itself.
Ant suggestions?

Fixed this setting a unique StatusBar colour for the whole app instead of doing it for each ViewController. It took only 2 steps:
Defined “View controller-based status bar appearance” = NO on MyAppName-Info.plist
Added the following line to my - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions AppDelegate function
[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent];
It worked for me =)

Related

Cannot hide status bar in iOS7

I just upgraded my iPhone 5 iOS 7 to four beta version. Now when I run my app from Xcode 5 on this iPhone, status bar doesn’t hide, even though it should.
Not Working:
[[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation:UIStatusBarAnimationFade];
Not Working:
[UIApplication sharedApplication].statusBarHidden = YES;
Can't login to Apple Developer Forums
in your apps plist file add a row call it "View controller-based status bar appearance" and set it to NO
Note that this simply does not work, if you are using UIImagePickerController in the app.
from http://www.openfl.org/developer/forums/general-discussion/iphone-5ios-7-cant-hide-status-bar/, mgiroux's solution
Add method in your view controller.
- (BOOL)prefersStatusBarHidden {
return YES;
}
In the Plist add the following properties.
-> Status bar is initially hidden = YES
-> View controller-based status bar appearance = NO
Add both - now the status bar will disappear.
To hide Status Bar on a Single view, you should use:
[[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation:UIStatusBarAnimationSlide];
At first, this didn't work for me, and then a saw in the documentation of this method that says:
// Setting statusBarHidden does nothing if your application is using the default UIViewController-based status bar system.
This has to be done on the plist file, adding the key View controller-based status bar appearance set to NO.
And then it worked.
In order to use the legacy UIApplication method to hide/show the status bar, your app must set a plist value for iOS 7:
View-Controller Based Status Bar Appearance = NO
This value is set to YES by default. If you change it to NO, you can use the legacy methods. If you leave it set to YES, you can still hide the status bar, but it's up to each view controller subclass in your app to override: prefersStatusBarHidden to return YES.
Any time your app needs the status bar appearance or visibility to change, and View-Controller Based Status Bar Appearance is set to YES, your outermost view controller needs to call:
setNeedsStatusBarAppearanceUpdateAnimation
To hide status bar in iOS7 you need 2 lines of code
inapplication:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions write
[application setStatusBarHidden:YES];
in info.plist add this
View-Controller Based Status Bar Appearance = NO
There are so many combinations suggested for this issue, but the problem is that iOS 6 and 7 use different methods to hide the status bar. I have never been successful setting the plist settings to enable the iOS6-style behaviour on iOS 7, but if you are building your app to support iOS 6+, you need to use 3 methods at once to ensure a particular view controller hides the status bar:
// for ios 7
- (BOOL)prefersStatusBarHidden{
return YES;
}
// for ios 6
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
[[UIApplication sharedApplication] setStatusBarHidden:YES];
}
- (void)viewWillDisappear:(BOOL)animated {
[super viewWillDisappear:animated];
// explicitly set the bar to show or it will remain hidden for other view controllers
[[UIApplication sharedApplication] setStatusBarHidden:NO];
}
This should work regardless of your plist settings.
I had to do both changes below to hide the status bar:
Add this code to the view controller where you want to hide the status bar:
- (BOOL)prefersStatusBarHidden
{
return YES;
}
Add this to your .plist file (go to 'info' in your application settings)
View controller-based status bar appearance --- NO
Then you can call this line to hide the status bar:
[[UIApplication sharedApplication] setStatusBarHidden:YES];
Just add these 2 lines in info.plist file. It will make the fix for iOS7 and older version both.
Status bar is initially hidden = YES
View controller-based status bar appearance = NO
Navigate to the project and select Targets -> General and see the "Status Bar style ...Hide during application launch" check box will be checked. This will work.
Try this simple method:
- (void)viewWillAppear:(BOOL)animated
{
[[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation:UIStatusBarAnimationNone];
}
- (void)viewWillDisappear:(BOOL)animated
{
[[UIApplication sharedApplication] setStatusBarHidden:NO withAnimation:UIStatusBarAnimationNone];
}
The only thing that worked for me is to add the following in your plist
<key>UIStatusBarHidden</key>
<true/>
<key>UIViewControllerBasedStatusBarAppearance</key>
<false/>
The easiest method I've found for hiding the status bar throughout the entire app is by creating a category on UIViewController and overriding prefersStatusBarHidden. This way you don't have to write this method in every single view controller.
UIViewController+HideStatusBar.h
#import <UIKit/UIKit.h>
#interface UIViewController (HideStatusBar)
#end
UIViewController+HideStatusBar.m
#import "UIViewController+HideStatusBar.h"
#implementation UIViewController (HideStatusBar)
//Pragma Marks suppress compiler warning in LLVM.
//Technically, you shouldn't override methods by using a category,
//but I feel that in this case it won't hurt so long as you truly
//want every view controller to hide the status bar.
//Other opinions on this are definitely welcome
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wobjc-protocol-method-implementation"
- (BOOL)prefersStatusBarHidden
{
return YES;
}
#pragma clang diagnostic pop
#end
In plist add ----
View controller-based status bar appearance --- NO
In each viewController write
- (void) viewDidLayoutSubviews
{
CGRect viewBounds = self.view.bounds;
CGFloat topBarOffset = 20.0;
viewBounds.origin.y = -topBarOffset;
self.view.bounds = viewBounds;
[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent];//for status bar style
}
For status bar issue in iOS 7 but target should be 5.1 and above for the app
Many of the answers on this thread work, but it's my understanding if you're trying to do anything dynamic you'll eventually need to call:
[self performSelector:#selector(setNeedsStatusBarAppearanceUpdate)];
Steps For Hide the status bar in iOS 7:
1.Go to your application info.plist file.
2.And Set, View controller-based status bar appearance : Boolean NO
Hope i solved the status bar issue.....
For iOS 7 in a single view use in viewWillappear method:
[[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation:NO];
For display the status bar use:
[[UIApplication sharedApplication] setStatusBarHidden:NO withAnimation:NO];
-(BOOL)prefersStatusBarHidden
{
return YES;
}
In Info Plist file Add a row for following property
Property Name : View controller-based status bar appearance
Value : NO
Try adding the following method to your app's root view controller:
- (BOOL)prefersStatusBarHidden
{
return YES;
}
I tried all these options posted here on my project and they would not work. I thought it could be to do with the fact I had updated my Xcode and then the app to iOS 7 and some settings had got messed up somewhere. I decided To build a completely new project for it and after simple just setting: "Status bar is initially hidden = YES" and "View controller-based status bar appearance = NO" as stated by many others it worked correctly (i.e. no status bar).
So my advice if you are working on a project which has been updated to iOS 7 from an old version and have tried all other options is to build a new project.
For 2019 ...
To make an app with NO status bars,
Click info.plist, right-click to "Add row".
Add these two, with these settings:
That's all there is to it.
You can check this code, pod UIViewController+ODStatusBar
For Swift 2.0+ IOS 9
override func prefersStatusBarHidden() -> Bool {
return true
}
To hide status bar for specific viewController
- (BOOL)prefersStatusBarHidden {
return YES;
}
For setting status bar Hidden for application:
set View controller-based status bar appearancetoNO in .plist
and in application: didFinishLaunchingWithOptions: set:
[application setStatusBarHidden:YES];
Note: setStatusBarHidden: deprecated
OR
in Project settings -> General Tab ->Deployment Info
Check Hide Status bar box.
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
application.statusBarHidden = YES;
return YES;
}
I'm not sure why you "can't login to the Apple Developer Forums", but (without violating the NDA) you can also hide your statusBar through Xcode. It's a general setting on your application target.

Setting a Storyboard Tab Controller, More Tab's Navigation Bar Colour

So throughout my application I implement Navigation Bars with the style Black Opaque.
The Problem
I can't seem to set the colour of the Navigation Bar that presents itself when the user selects the automatically generated More Tab
The Question
How do I set the colour of this Navigation Bar to Black Opaque?
Thanks in advance.
Yes, I'm one of those sad people who is now answering their own question :P Hopefully it helps..
So you need to get a reference to the TabBarController in your app delegate and then change the style of the more navigation controller from there. The code below shows you how and where..
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
// Override point for customization after application launch.
UITabBarController *_tabController = (UITabBarController*)_window.rootViewController;
_tabController.moreNavigationController.navigationBar.barStyle = UIBarStyleBlackOpaque;
return YES;
}

Hide status bar for entire app

I create views programmatically. To hide status bar in view I use
[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation:NO];
in viewDidload method. The problem is every view have to implement the code above to be status bar hidden. Is there a way (programmatically) to set status bar hidden just in one place in the app so entire app to be without the status bar ?
I have tried to add this in AppDelegate, but it doesn't work.
Open your app plist file MyApp-Info.plist and add a row with the Status bar is initially hidden and the YES value.
EDIT:
If you want to do it programmatically, add this in your ApplicationDidFinishLaunching :
[UIApplication sharedApplication].statusBarHidden = YES;
If you are targeting the devices with iOS > 3.2, then use the following code in application:didFinishLaunchingWithOptions: method in AppDelegate class.
[[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation:UIStatusBarAnimationNone];
just put key "Status bar is initially hidden" as YES in Info.plist file.
you will get hide status bar throughout the application.
If you want to do it by problematically, then just put this code in Appdelegate.m file of your project.
[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation:NO];
Instead of creating new views based on UIView, subclass UIView (we can call it SummercView) and add a viewDidLoad method to it that looks like:
- (void) viewDidLoad
{
[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation:NO];
[super viewDidLoad];
}
And then in your xib or storyboard files, set the views where you want to hide the status bar to use SummercView instead of UIView.
And of course #Aadhira's answer is good, too. +1 to him/her.
Couldn't you create a view class which did this in viewDidLoad, and have your views be subclasses of it? They'd still each have to hide the status bar, but at least you wouldn't have to duplicate the code in each subclass.

UITextField not working inside a UITabBarController with IOS5

Are there any restrictions on a UITextField when placed inside a tabview which not the main interface. In other words
Working fine scenario
1. A tab based application, with one of the view having a UITextField.
2. The tabview is the main interface for the application.
This works fine without any glitches
Not-working so fine scenario.
1. A tab based application, but the tab view is not the mainview.
2. There is another view MainWindow.xib with some intro animation, which then calls and shows the tabview.
3. UITextfield in such tabviews does'nt seem to work - especially in IOS5. Both methods work fine till IOS 4.3
4. The textfield is visible, but tapping it does not show any keyboard, if i call becomeFirstResponder via code, the keyboard is shown but is not responsive.
Any suggestions
The code is pretty standard
in the AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
tabViewController = [[tabView alloc] initWithNibName:#"tabView" bundle:nil];
[self.window addSubview:tabViewController.view];
//self.window.rootViewController=tabViewController
[self.window makeKeyAndVisible];
return YES;
}
tabViewController has a ProfileViewController with a simple textfield.
The textfield works fine if i do this
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
tabViewController = [[tabView alloc] initWithNibName:#"tabView" bundle:nil];
profileView=[[Profile alloc] initWithNibName:#"Profile" bundle:nil];
//calling the view directly without using a tab view
[self.window addSubview:profileView.view];
[self.window makeKeyAndVisible];
return YES;
}
Is there something else that needs to be done for IOS5 when the tab view is not the main interface? I have been cracking my head at this for a few days, all my apps with a UITextfield inside a tabview are not usable in ios5. Any help is highly appreciated
Edit: Uploaded the project file http://www.mediafire.com/?xjuc4udlph78saj - XCode 4.2 on Lion
It is a simple project with two options, Creating a tabbarcontroller from the delegate itself, and i also have a view(tabView) with a tabbarcontroller. There are 2 views for the tabbar FirstViewController & SecondViewController.
In the AppDelegate.m if using method 1(create UITabBarController inside AppDelegate, all is well). If i choose to add a subview of tabView, the uitextfield does not work.
I have not really handled the releasing of objects, since this is test project and it is only for proof of concept.
Thanks
After hours of searching, fiddling and experimenting. I have found out the solution.
This seems to happen when there are more than one UIWindow in the application.
In my case, i was diong this
AppDelegate starts off with its own UIWindow Once i have played some
startup animations, i try to display another view with a
tabbarcontroller, and ofcoures a window to hold the UITabBarController
The second window (even after setting it to makeKeyAndVisible) seems
to be blocking keyboard events fore UITextField inside the
UITabBarController.
The following has worked for me:
Rather than having the second view with its own window, i had it with a UITabBarController, and a UIView/UIWindow(this is for the sake of having a default view for the nib file). And when i needed to show the tabbarview i have used this
[[[UIApplication sharedApplication] keyWindow] setRootViewController:TabBar]
I am not sure of a better way, but that have worked for me. In short, i have found that having another UIWindow inside the app causes issues with becomeFirstResponder.

iPad SplitView Application not taking up entire window

I am working on a split-view based application for the iPad. I created a menu overlay system that has a button that leads into the split-view application. See comment for image
When you click the enter button, however, it results in this:
http://commandoswat.webs.com/Screen%20shot%202010-09-16%20at%201.37.11%20PM.png
Here is my code for the application delegate:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after app launch.
mainMenuController = [[MainMenuController alloc]init];
mainMenuController.sWindow = window;
mainMenuController.sController = splitViewController;
// Add the split view controller's view to the window and display.
[window addSubview:mainMenuController.view];
[window makeKeyAndVisible];
return YES;
}
Here is my code for the MainMenuController Enter Button:
-(IBAction) enterButton{
[self.view removeFromSuperview];
[sWindow addSubview:sController.view];
}
How do I make the split view take up the entire screen?
Any suggestions?
Thanks
Looks to me that your detail view isn't sized properly, and/or doesn't have its autoresizingMask property set appropriately (to have flexible width).