How to hide iOS status bar

2019-01-01 17:04发布

In my iOS video app status bar is hidden in some view controllers. I have done this using following code.

[[UIApplication sharedApplication] setStatusBarHidden:YES];
  • It works for iOS 5 and iOS 6 , but not in iOS 7.

  • I tried with this in particular view controller,

Eg:

-(BOOL)prefersStatusBarHidden { return YES; }

It works well, but I cant show status bar again in the parent view controller.

20条回答
不流泪的眼
2楼-- · 2019-01-01 17:21

To hide status bar in iOS7 you need 2 lines of code

  1. in application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions write

     [[UIApplication sharedApplication] setStatusBarHidden:YES];
    
  2. in info.plist add this

     View-Controller Based Status Bar Appearance = NO
    
查看更多
公子世无双
3楼-- · 2019-01-01 17:21

Update for Swift 3:

Update Info.plist with the following info:

View controller-based status bar appearance: NO

Then, in a ViewController or elsewhere:

UIApplication.shared.isStatusBarHidden = true

查看更多
姐姐魅力值爆表
4楼-- · 2019-01-01 17:22

To hide your status bar in iOS7:

Open Your plist-file, then add a add a row called "View controller-based status bar appearance" and set its value to NO.

查看更多
时光乱了年华
5楼-- · 2019-01-01 17:26

In iOS10 all I needed to do is override the prefersStatusBarHidden var in my RootViewController (Swift):

override var prefersStatusBarHidden: Bool {
    return true
}
查看更多
萌妹纸的霸气范
6楼-- · 2019-01-01 17:26

From UIKit>UIApplication.h:

// Setting statusBarHidden does nothing if your application is using the default UIViewController-based status bar system.
@property(nonatomic,getter=isStatusBarHidden) BOOL statusBarHidden;
- (void)setStatusBarHidden:(BOOL)hidden withAnimation:(UIStatusBarAnimation)animation NS_AVAILABLE_IOS(3_2);

So should set View controller-based status bar appearance to NO

查看更多
看风景的人
7楼-- · 2019-01-01 17:30

Steps for hide status bar in iOS
1. open AppDelegate.m file, add application.statusBarHidden in didFinishLaunchingWithOptions method

 - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    // Override point for customization after application launch.
    application.statusBarHidden = YES;
    return YES;
    }
  1. open info.plist and set

View controller-based status bar appearance set NO

查看更多
登录 后发表回答