I have tried
[[UIApplication sharedApplication] setStatusBarHidden:YES];
This does nothing.
And I have looked in my Info.plist file for "View controller-based status bar appearance" but it's not there.
How can I hide the white status bar at the top of the screen (with the clock and battery charge) inside my app for Xcode 6? Thank you!
You need to override this method on each view controller unless you have that plist entry.
Objective-C
-(BOOL)prefersStatusBarHidden{
return YES;
}
Swift 2
override func prefersStatusBarHidden() -> Bool {
return true
}
Swift 3+
override var prefersStatusBarHidden: Bool {
return true
}
And don't forget to set (if you present a view controller by calling the presentViewController:animated:completion: method):
Objective-C
vcToBeShownWithoutStatusbar.modalPresentationCapturesStatusBarAppearance = YES;
Swift
vcToBeShownWithoutStatusbar.modalPresentationCapturesStatusBarAppearance = true
Documentation: https://developer.apple.com/reference/uikit/uiviewcontroller/1621453-modalpresentationcapturesstatusb
If you change status bar from some container view controller (eg. UINavigationController or UIViewController with child view controllers) and you would like to change view controller responsible for status bar you should use childViewControllerForStatusBarHidden: property. Eg:
Set first view controller instance always responsible for status bar management
Objective-C
- (UIViewController *)childViewControllerForStatusBarHidden {
return childViewControllers.first; // or viewControllers.first
}
Swift 2
override var childViewControllerForStatusBarHidden() -> UIViewController? {
return childViewControllers.first // or viewControllers.first
}
Swift 3+
override var childViewControllerForStatusBarHidden: UIViewController? {
return childViewControllers.first // or viewControllers.first
}
Set container view controller responsible for status bar management
Objective-C
- (UIViewController *)childViewControllerForStatusBarHidden {
return nil;
}
Swift 2
override func childViewControllerForStatusBarHidden() -> UIViewController? {
return nil
}
Swift 3+
override var childViewControllerForStatusBarHidden: UIViewController? {
return nil
}
Documentation:
https://developer.apple.com/documentation/uikit/uiviewcontroller/1621451-childviewcontrollerforstatusbarh
Go to Info.plist file
Hover on one of those lines and a (+) and (-) button will show up.
Click the plus button to add new key
Type in start with capital V and automatically the first choice will be View controller-based status bar appearance. Add that as the KEY.
Set the VALUE to "NO"
Go to you AppDelegate.m for Objective-C (for swift language: AppDelegate.swift)
Add the code, inside the method
For Objective-C:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
[application setStatusBarHidden:YES];
return YES;
}
For Swift:
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey:Any]?) -> Bool {
application.statusBarHidden = true
return true
}
Done! Run your app and no more status bar!
You can hide the status bar without writing a single line of code, it just requires two entries into the info.plist the first is
"View controller-based status bar appearance" set to NO
the second is
"Status bar is initially hidden" set to YES
You can add that row to your Info.plist file if it isn't there. Just go to the project in Xcode, go to the "Info" section, and hover over one of the existing rows. A "+" button should appear, allowing you to add a line and input "View controller-based status bar appearance".
For iOS 10 with Swift 3 you should use:
override var prefersStatusBarHidden: Bool {
get {
return true
}
}
Open info.plist
"View controller-based status bar appearance" set to NO
"Status bar is initially hidden" set to YES
Done
No need to write a line of code...Cheers
If you use UIDocumentInteractionController to show data then you never hide status bar so i have alternate of this
[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent];
this line change the color of status bar content into white
Related
I will accept answers in both swift and objective-c as the translation is fairly easy.
I want to display a tab bar with a splash screen, but I don't want that splash screen to be in the tab bar items for selection.
My setup now (below) shows the landing screen as the first displayed controller when the tab bar displays. However, I want that tab bar item hidden. Only the other three tabs should be selectable by a user. How do I do this?
//Create and add landing view
navigation = UINavigationController()
landingView = WGMLandingViewController(nibName: XIBFiles.LANDINGVIEW, bundle: nil)
navigation.pushViewController(landingView, animated: false)
navigation.title = "Landing View"
controllers.append(navigation)
//Create and add library view
navigation = UINavigationController()
libraryView = WGMLibraryViewController(nibName: XIBFiles.LIBRARYVIEW, bundle: nil)
navigation.pushViewController(libraryView, animated: false)
navigation.title = "Learn More"
controllers.append(navigation)
//Create and add pad view
navigation = UINavigationController()
orderPadView = WGMOrderPadViewController(nibName: XIBFiles.ORDERPADVIEW, bundle: nil)
navigation.pushViewController(orderPadView, animated: false)
navigation.title = "Order Pad"
controllers.append(navigation)
//Create and add lookup view
navigation = UINavigationController()
partLookupView = WGMLookupViewController(nibName: XIBFiles.LOOKUPVIEW, bundle: nil)
navigation.pushViewController(lookupView, animated: false)
navigation.title = "Lookup"
controllers.append(navigation)
//Set up controller list
self.setViewControllers(controllers, animated: false)
Apple's existing APIs don't allow you to do this, but we it shouldn't too hard to sub-class UITabBarController and get it to do what you want.
Ok.. my original answer won't work these days.. or I've gone senile and it never worked and I did something else. *cough*
So anyway, you'll have to roll your own tab bar controller. It's not so hard (just time consuming) now that we have containment view controllers and you can still use the UITabBar.
Create a UIViewController (your tab bar controller) and stick a UITabBar and a UIView in it.
Create an outlet for the view (this is where your view controllers will go) and tab bar
Configure the UITabBar however you'd like it.
Set the delegate of the UITabBar to be your view controller and implement the didSelectItem method.
Create a method to load your splash screen view controller and stick in your viewDidLoad or where you want it.
Something like
- (void)loadSplashScreen {
// load in the child view controller
UIViewController *splashScreenController = ...;
[self loadChildViewController:splashScreenController];
// make sure nothing in the tab bar is selected
self.tabBar.selectedItem = nil;
}
Then also add code to load the appropriate view controller whenever the various tabs are selected
- (void)tabBar:(UITabBar *)tabBar didSelectItem:(UITabBarItem *)item {
// logic to figure out which view controller you want based on `item`
// ...
UIViewController = ...;
[self loadChildViewController:viewController];
}
- (void)loadChildViewController:(UIViewController *)viewController {
[self removeCurrentTabController]; // remove the existing one, if any using whatever memory management techniques you want to put in place.
[self addChildViewController:viewController];
[self.tabView addSubview:viewController.view]; // where self.tabView is your outlet from step 2.
}
My application has a dark background, but in iOS 7 the status bar became transparent. So I can't see anything there, only the green battery indicator in the corner. How can I change the status bar text color to white like it is on the home screen?
Set the UIViewControllerBasedStatusBarAppearance to YES in the .plist file.
In the viewDidLoad do a [self setNeedsStatusBarAppearanceUpdate];
Add the following method:
- (UIStatusBarStyle)preferredStatusBarStyle
{
return UIStatusBarStyleLightContent;
}
Note: This does not work for controllers inside UINavigationController, please see Tyson's comment below :)
Swift 3 - This will work controllers inside UINavigationController. Add this code inside your controller.
// Preferred status bar style lightContent to use on dark background.
// Swift 3
override var preferredStatusBarStyle: UIStatusBarStyle {
return .lightContent
}
Swift 5 and SwiftUI
For SwiftUI create a new swift file called HostingController.swift
import Foundation
import UIKit
import SwiftUI
class HostingController: UIHostingController<ContentView> {
override var preferredStatusBarStyle: UIStatusBarStyle {
return .lightContent
}
}
Then change the following lines of code in the SceneDelegate.swift
window.rootViewController = UIHostingController(rootView: ContentView())
to
window.rootViewController = HostingController(rootView: ContentView())
Alternatively, you can opt out of the view-controller based status bar appearance:
Set View controller-based status bar appearance to NO in your Info.plist.
Call [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent];
Note: This method has been deprecated in iOS9. Use preferredStatusBarStyle on the UIViewController instead. (see Apple Developer Library)
You can do this without writing any line of code!
Do the following to make the status bar text color white through the whole app
On you project plist file:
Status bar style: Transparent black style (alpha of 0.5)
View controller-based status bar appearance: NO
Status bar is initially hidden: NO
Note: The most upvoted answer does not work for iOS 7 / 8
In Info.plist set 'View controller-based status bar appearance' as NO
In AppDelegate add
[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent];
to
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions{
...
}
This solution works for iOS 7 / 8.
For me, nothing happened with using all the things in the other answers (and from other sources/documentation). What did help was to set the Navigation Bar Style to "Black" in the XIB. This changed the text to white without any code at all.
None of that worked for me, so here is a working solution...
In Info.plist, add a row:
UIViewControllerBasedStatusBarAppearance, and set the value NO.
Then in AppDelegate in didFinishLaunchingWithOptions, add these rows:
[application setStatusBarHidden:NO];
[application setStatusBarStyle:UIStatusBarStyleLightContent];
You dont need to do any code for this
You need to add "View controller-based status bar appearance" key in info.plist as follows:
& set its value type to Boolean & value to NO.
Then click on project settings,then click on General Tab & under Deployment Info set the preferred status bar style to .Light as follows:
Thats it.
Just two steps as following:
Step 1:
Under the Info tab of the project target, Add Row:
UIViewControllerBasedStatusBarAppearance, set value NO.
Step 2:
In the project AppDelegate.m:
- (BOOL)application:(UIApplication *)application
didFinishLaunchingWithOptions:(NSDictionary *)launchOptions{
…
[application setStatusBarStyle:UIStatusBarStyleLightContent];
…
}
This works in Golden Master iOS 7 and Xcode 5 GM seed and iOS7 SDK released on September 18th, 2013 (at least with navigation controller hidden):
Set the UIViewControllerBasedStatusBarAppearance to NO in the
Info.plist.
In ViewDidLoad method or anywhere, where do you want to change
status bar style:
[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent];
In case your UIViewController is inside a UINavigationController you will have to set the BarStyle:
-[UINavigationBar setBarStyle:UIBarStyleBlack]
Original Answer is here
https://devforums.apple.com/message/844264#844264
If you have an embedded navigation controller created via Interface Builder, be sure to set the following in a class that manages your navigation controller:
-(UIStatusBarStyle)preferredStatusBarStyle{
return UIStatusBarStyleLightContent;
}
That should be all you need.
I'm using Xcode 6 beta 5 on a Swift project, for an iOS 7 app.
Here is what I did, and it works:
info.plist:
Go to Project -> Target,
Then set Status Bar Style to Light. It makes status-bar white from the launch screen.
Then set View controller-based status bar appearance equal to NO in Info.plist.
In Swift 3 is very easy just with 2 steps.
Go to your info.plist and change the key View controller-based status bar appearance to "NO".
Then in the Appdelegate just add this line in didfinishlaunchingwithoptions method
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
// Override point for customization after application launch.
UIApplication.shared.statusBarStyle = .lightContent
return true
}
this has been deprecated in iOS9 now you should do override this property in the rootviewcontroller
doing this has been deprecated in iOS 9 should do this on the rootviewcontroller
override var preferredStatusBarStyle: UIStatusBarStyle {
return .lightContent
}
In AppDelegate.m, add the following.
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions{
[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent];
}
And in the Plist file, set 'View controller-based status bar appearance' to NO.
Simply In App Delegate:
[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent];
In Swift 5, Follow the below steps:
Add key UIViewControllerBasedStatusBarAppearance and set value to false in Info.plist
Add key UIStatusBarStyle and set value to UIStatusBarStyleLightContent
Well, this is really working like a piece of cake for me.
Go to your app's info.plist.
Set View controller-based status bar appearance to NO
Set Status bar style to UIStatusBarStyleLightContent
Then go to your app's delegate and paste in the following code where you set your windows's RootViewController.
#define SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] != NSOrderedAscending)
if (SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(#"7.0"))
{
UIView *view=[[UIView alloc] initWithFrame:CGRectMake(0, 0,320, 20)];
view.backgroundColor=[UIColor colorWithRed:0/255.0 green:0/255.0 blue:0/255.0 alpha:1.0];
[self.window.rootViewController.view addSubview:view];
}
Bingo. It's working for me.
iOS 7 allows individual view controllers to determine the appearance of the status bar, as described by the Apple developer documentation:
iOS 7 gives view controllers the ability to adjust the style of the status bar while the app is running. A good way to change the status bar style dynamically is to implement preferredStatusBarStyle and—within an animation block—update the status bar appearance and call setNeedsStatusBarAppearanceUpdate.
Setting the status bar appearance globally is a two-step process.
First, you need to tell iOS that you don't want to set the status bar appearance on a view-by-view basis.
Then you need to take charge and actually set the new global status bar style.
To disable view-by-view status bar control, you'll need to set the View controller-based status bar appearance property in Info.plist.
Open the Project Navigator and select the project for your iOS app, then select the Info tab.
Hover over a row, then click the plus sign that appears to add a new property to your .plist.
Enter View controller-based status bar appearance in the Key field, then make sure the Type field is set to Boolean. Finally, enter NO in the Value field.
To set a global style for the status bar, add another property under the Info tab with a key of Status bar style, a Type of String and a Value of Opaque black style.
Here's a blog post with a little more detail and some sample code:
http://codebleep.com/setting-the-status-bar-text-color-in-ios-7/
Xcode constantly seems to change this, so this is the latest.
As of 2021 - Swift 5, Xcode 12
To change the status bar to white:
Open your Info.plist.
Add key UIViewControllerBasedStatusBarAppearance and set value to No (false). The human readable version of this is "View controller-based status bar appearance".
Add key UIStatusBarStyle and set value to UIStatusBarStyleLightContent (i.e., "Light Content").
Answer updated for for Xcode GM Seed:
In Info.plist put View controller-based status bar appearance as NO
In the project, set:
In ViewDidLoad:
[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent];
No need do some extra , just write this code in your viewController and get status bar color white
- (UIStatusBarStyle)preferredStatusBarStyle{return UIStatusBarStyleLightContent;}
I think all the answers do not really point the problem because all of them work in specific scenarios. But if you need to cover all the cases follow the points bellow:
Depending on where you need the status bar light style you should always have in mind these 3 points:
1)If you need the status bar at the launch screen or in other places, where you can't control it (not in view controllers, but rather some system controlled elements/moments like Launch Screen)
You go to your project settings
2) if you have a controller inside a navigation controller
You can change it in the interface builder as follows:
a) Select the navigation bar of your navigation controller
b) Then set the style of the navigation bar to "Black", because this means you'll have a "black" -> dark background under your status bar, so it will set the status bar to white
Or do it in code as follows
navigationController?.navigationBar.barStyle = UIBarStyle.Black
3) If you have the controller alone that needs to have it's own status bar style and it's not embedded in some container structure as a UINavigationController
Set the status bar style in code for the controller:
Here is Apple Guidelines/Instruction about status bar change. Only Dark & light (while & black) are allowed in status bar.
Here is - How to change status bar style:
If you want to set status bar style, application level then set UIViewControllerBasedStatusBarAppearance to NO in your `.plist' file.
if you wan to set status bar style, at view controller level then follow these steps:
Set the UIViewControllerBasedStatusBarAppearance to YES in the .plist file, if you need to set status bar style at UIViewController level only.
In the viewDidLoad add function - setNeedsStatusBarAppearanceUpdate
override preferredStatusBarStyle in your view controller.
-
override func viewDidLoad() {
super.viewDidLoad()
self.setNeedsStatusBarAppearanceUpdate()
}
override var preferredStatusBarStyle: UIStatusBarStyle {
return .lightContent
}
Set value of .plist according to status bar style setup level.
Here is some hacky trick to change/set background color for status bar during application launch or during viewDidLoad of your view controller.
extension UIApplication {
var statusBarView: UIView? {
return value(forKey: "statusBar") as? UIView
}
}
// Set upon application launch, if you've application based status bar
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
UIApplication.shared.statusBarView?.backgroundColor = UIColor.red
return true
}
}
or
// Set it from your view controller if you've view controller based statusbar
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
UIApplication.shared.statusBarView?.backgroundColor = UIColor.red
}
}
Here is result:
This is documented in the iOS 7 UI Transition Guide, which you need an Apple developer ID to access directly. The relevant excerpt:
Because the status bar is transparent, the view behind it shows through. [...] Use a UIStatusBarStyle constant to specify whether the statusbar content should be dark or light:
UIStatusBarStyleDefault displays dark content. [...]
UIStatusBarStyleLightContent displays light content. Use when dark content is behind the status bar.
Also possibly of interest:
In iOS 7, you can control the style of the status bar from an individual vew controller and change it while the app runs. To opt in to this behavior, add the UIViewControllerBasedStatusBarAppearance key to an app's Info.plist file and give it the value YES.
I'd definitely recommend having a look through the document, which, again, you can access with your Apple developer ID.
Simply calling
[[UINavigationBar appearance] setBarStyle:UIBarStyleBlack];
in the
-(BOOL)application:(UIApplication *)application
didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
}
method of my AppDelegate works great for me in iOS7.
In my case for Swift 5, I added these lines:
override func viewDidAppear(_ animated: Bool) {
navigationController?.navigationBar.barStyle = .black
}
override var preferredStatusBarStyle: UIStatusBarStyle {
return .lightContent
}
I did some things different and it works for me.
With no changes in code, I did config my .plist file like this:
View controller-based status bar appearance > NO
Status bar style > UIStatusBarStyleLightContent (simple string)
I hope it helps.
edit
For each view controller I change the "status bar"'s Simulated Metrics property, in storyboard, from "inferred" to "Light Content"
in info.plist set the field value NO View controller-based status bar appearance and set statusbar style light in target > general setting.
Just to summarize, edit your project Info.plist and add:
View controller-based status bar appearance : NO
Status bar style : Opaque black style
or if you have raw key/value plist
UIViewControllerBasedStatusBarAppearance : NO
UIStatusBarStyle : Opaque black style
If you want the same result with Swift, you can use this code in your AppDelegate.swift file :
UINavigationBar.appearance().barStyle = .BlackTranslucent
And the text of your status bar will be white :-) !
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.
I have an iPhone app with a root view controller (VC) of UITabBarController (set to portrait orientation) with several tabs, one of which is a simple UIViewController. In that UIViewController is a single button - "Play Video", which, when clicked opens a modal view of the video (and automatically starts playing the video). The video view is a UIWebView in a UIViewController. I've been trying to get the Web View's VC to change orientation to landscape but have not had any luck.
I've looked around and understand that if you have a Tab Bar or a Nav controller, all children VCs will be the same orientation as the parent - makes sense. This is why I made the web view's VC modal, hoping this is a way around the orientation issue.
My question is: is this accurate - that using modal will not require the web view VC to be portrait and can respond to the shouldAutorotateToInterfaceOrientation method (even though I have not yet been able to get it to work)?
BTW, using iOS 6.
Thanks in advance.
Apparently in ios6 and above, the way rotation works is different. So what you have to do is the following
In your .plist support all 4 orientations.
Subclass the UITabBarController (for e.g: CustomTabBarController)
In the CustomTabBarController put the following lines of code
-(NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskPortrait;
}
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
return UIInterfaceOrientationPortrait;
}
In your app delegate or where ever you are initializing UITabBarController, replace those instances with CustomTabBarController instances.
In your modal controller put the lines
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
return UIInterfaceOrientationLandscapeLeft;
}
-(BOOL)shouldAutorotate{
return NO;
}
And it should all work.
Apparently the trick, I found is that, UITabBarController will not listen to your instructions. It will support all the orientations you mention in the .plist.
There fore you have to subclass it.
I tried doing all of the above and it works fine. Do let me know and I can send you the code if you want.
Try this. Just have portrait set in the summary screen, then in the app delegate, implement this:
- (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window {
return UIInterfaceOrientationMaskAll;
}
In the tab bar controller (and no other rotation code):
-(BOOL)shouldAutorotate {
return NO;
}
And finally, in the modal view controller:
-(BOOL)shouldAutorotate {
return YES;
}
- (NSUInteger)supportedInterfaceOrientations {
return UIInterfaceOrientationMaskAll;
}
I have created an App for Mac Desktop, it is working, but Apple rejected it because when we run the App and close it by using "X", the we can not re-open it from the dock though the App icon is still there but it doesn't open the App again and the main issue for that I am struggling is that "If we close the App then in the menu bar there is no option to open it" other App which I have seen does that.
What should I do?
Here's an answer for Swift 3:
Conform to NSWindowDelegate in your View Controller class. Then hide the window instead of closing it by overriding the following method.
self.view.window?.delegate = self
func windowShouldClose(_ sender: Any) -> Bool {
NSApplication.shared().hide(self)
return false
}
Then unhide the application when the app icon is clicked in the dock.
func applicationDidBecomeActive(_ notification: Notification) {
NSApplication.shared().unhide(self)
}
To implement simple show/hide functionality for the red (x) button, make your App Delegate class the window delegate for your main window, as well.
Then add the following code to it:
- (BOOL)windowShouldClose:(id)sender {
[[NSApplication sharedApplication] hide:self];
return NO;
}
- (void)applicationDidBecomeActive:(NSNotification *)notification {
[[NSApplication sharedApplication] unhide:self];
}
my 2 cernts for swift 5/Xcode 10
note: You can call these methods also in ViewController (if useful) to prevent splitting code between NASWindow/NSView-Controllers.
in this case:
class ViewController: NSViewController, **NSWindowDelegate**
{
...
override func viewWillAppear() {
// we choose to delegate ourselves. must be done here, in viewDidLoad window is nil
let window = self.view.window
window!.delegate = self
}
...
no neeed to pass self.. : (as per other guys above.)
func windowShouldClose(_ sender: NSWindow) -> Bool {
NSApplication.shared.hide(nil)
return false // prevent closing.
}
func applicationDidBecomeActive(_ notification: Notification) {
NSApplication.shared.unhide(nil)
}