iOS 开发过程中可能会有这样的需求。
为了不影响app内容的显示,将顶部的状态栏(现实信号,时间,电量)隐藏
默认状态栏一直是存在的
![4170753-654c9da7c3878cca.png](https://i-blog.csdnimg.cn/blog_migrate/1b266261f3c837389cc7fcf370428e34.webp?x-image-process=image/format,png)
方法一,
适用于修改个别页面的状态栏
我们可以通过设置ViewController的属性来隐藏
在 viewDidLoad 方法中添加如下代码
[self prefersStatusBarHidden];
[self performSelector:@selector(setNeedsStatusBarAppearanceUpdate)];
再实现一个方法
- (BOOL)prefersStatusBarHidden
{
return YES;//隐藏为YES,显示为NO
}
好了 我们运行一下看看效果
方法二,
适用于修改所有状态栏
我们找到项目的 info.plist文件(项目自动创建的,一般默认在Supporting Files 下)
![4170753-fc465d10cf0fdfed.png](https://i-blog.csdnimg.cn/blog_migrate/6848d2cac006aa92d01c0c0740867bf3.webp?x-image-process=image/format,png)
查看一下有没有这两个key
Status bar is initially hidden (value:YES)
View controller-based status bar appearance (value:NO)
如果没有 点击+添加
![4170753-bc147033af294571.png](https://i-blog.csdnimg.cn/blog_migrate/1f1d463a1c19fd209a3910852875e130.webp?x-image-process=image/format,png)
完成之后 效果如下
![4170753-56afa86d6439c7e3.png](https://i-blog.csdnimg.cn/blog_migrate/998b26f9ae40d187245b4cf414210872.webp?x-image-process=image/format,png)
运行项目 看看效果 是不是 隐藏的,方法二出来之后所有页面不用设置 默认都是 隐藏状态栏的