IOS状态栏隐藏设置

来源:互联网 发布:哪些网游支持mac 编辑:程序博客网 时间:2024/06/05 09:00

一.用代码设置状态栏的显示和隐藏:

在info.plist文件中,添加View controller-based status bar appearance项,默认其设为YES,则View controller对status bar的设置优先级高于application的设置。View controller-based status bar appearance为NO则以application的设置为准,view controller的prefersStatusBarHidden方法无效,是根本不会被调用.

View controller-based status bar appearance为 YES时设置隐藏的方法为[[UIApplication shareApplication] setStatusBarHidden:YES],该方法虽然可以使用,但是在 ios9之后,苹果官方不推荐使用该方法了,苹果推荐使用每个 ViewController 中去控制状态栏的方法,在 ViewController 中复写perfersStatusBarHidden方法复写如下:

-(BOOL)perfersStatusBarHidden {

return YES;

}

修改方法的返回值可设置状态栏的隐藏请款,前提是在 View controller-based status bar appearance 为 YES;

同样的方法设置状态栏的样式:复写的方法为

- (UIStatusBarStyle)preferredStatusBarStyle {

return UIStatusBarStyleLightContent;

}

二.用 plist 设置状态栏的显示和隐藏:

在 plist 中添加Status bar is initially hidden 设置其值为 YES,状态栏就会隐藏,或者在项目的 general 中Deployment info 中勾选 hide status bar ,这样就设置状态栏隐藏了;

原创粉丝点击