• Status bar


    (一)设置状态栏显示和隐藏
    1、通过 Info.plist 文件增加字段,控制状态栏全局显示和隐藏
    • 在 Info.plist 文件中增加字段 Status bar is initially hidden  设置为 YES ,那么 app 在 LaunchScreen 页面隐藏状态栏
    • 在 Info.plist 文件增加字段 View controller-based status bar appearance 设置为 YES,那么app默认所有页面都会显示状态栏
    2、通过代码,控制状态栏全局显示和隐藏
    • 在 Info.plist 文件 View controller-based status bar appearance 设置为 NO时,代码设置状态栏才会起作用。
    • 在 AppDelegate.m 中添加代码 [[UIApplication sharedApplication] setStatusBarHidden:NO];
    3、通过代码,控制状态栏局部显示和隐藏
    • 在 Info.plist 文件 View controller-based status bar appearance 设置为 YES
    • 在需要隐藏状态栏的VC中重写写法 - (BOOL)prefersStatusBarHidden { return YES;},返回YES
     
     
    (二)设置状态栏颜色
    1、设置状态栏文字部分的颜色
    • 全局文字颜色:在 Info.plist 增加key值 Status bar style,value可以设置 UIStatusBarStyleDefault (默认黑色)和 UIStatusBarStyleLightContent (白色)。
    • 全局文字颜色:在 Info.plist 文件 View controller-based status bar appearance 设置为 NO时,且在 AppDelegate.m 中添加2行代码 [[UIApplication sharedApplication] setStatusBarHidden:NO];   [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent]; 即可!注意:此处 Info.plist中添加的key值对应的value必须为NO,若为YES,则代码不起作用。
    • 局部文字颜色:此处分2种不同情况
               首先设置,在 Info.plist 文件 View controller-based status bar appearance 设置为 YES
               a. ViewController 不嵌套在 UINavigationController 中,需要设置以下
                    重写 UIViewController 方法 - (UIStatusBarStyle)preferredStatusBarStyle { return UIStatusBarStyleDefault; }
                b. ViewController 为 UINavigationController 的rootVC,需要设置以下
                    继承 UINavigationController 写一个子类,然后重写方法:
                    - (UIStatusBarStyle)preferredStatusBarStyle {
                            return self.topViewController.preferredStatusBarStyle;
                    }
     
    关于以上状态栏的显示和隐藏、文字或背景颜色均为亲测,若存在问题,麻烦留言@我!
  • 相关阅读:
    好久没锻炼
    liunx下安装第三方Python(PIP安装)
    Mysql和SqlServer互相转换
    sqlmap使用笔记
    查找域控的几个常用方法
    ssh的一些小操作
    使用theHarvester 进行邮箱和子域名的收集
    python实现大文件分割与合并
    python中MySQLdb模块用法实例
    2. Shell编程第二讲
  • 原文地址:https://www.cnblogs.com/xiu619544553/p/7928680.html
Copyright © 2020-2023  润新知