iOS彻底隐藏app状态栏StatusBar的方法汇总

方法一:
整个app中隐藏
1.首先工程的.plist文件中View controller-based status bar appearance这一栏必须设置为YES
2.再修改以下代码
//For Objective-C:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
  [application setStatusBarHidden:YES];

  return YES;
}
//For Swift:

func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject:AnyObject]?) -> Bool {
  application.statusBarHidden = true

  return true
}
方法二:
在单个视图隐藏:
1.首先工程的.plist文件中View controller-based status bar appearance这一栏设置为NO;
Status bar is initially hidden设置为YES。
2.再添加以下代码
//For Objective-C:

- (BOOL)prefersStatusBarHidden {
  return YES;
}
//For Swift:

override func prefersStatusBarHidden() -> Bool {
  return true
}


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
//Firstly, View controller-based status bar appearance in the .plist file must be set to YES.

//If you want status bar to be hidden in the whole app:
//For Objective-C:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
  [application setStatusBarHidden:YES];

  return YES;
}
//For Swift:

func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject:AnyObject]?) -> Bool {
  application.statusBarHidden = true

  return true
}
//If you want status bar is disappeared in Specify View Controller, in .m file, just implement:
//For Objective-C:

- (BOOL)prefersStatusBarHidden {
  return YES;
}
//For Swift:

override func prefersStatusBarHidden() -> Bool {
  return true
}

                                       
                      
博主

这货来去如风,什么鬼都没留下!!!

相关推荐

嗨、骚年、快来消灭0回复。

028402;您的ip地址是54.90.237.148; 当前围观人数:2

橘花2支持在线更新了,点我下更新支持文档然后托给橘花,再点SSP面板右键更新