iOS--Adjustment control method of status bar

In different demand scenarios, we will encounter situations where the font color of the status bar is displayed as dark or light, or we may encounter situations where we need to hide the status bar. Here are some basic operations on the status bar. Note that the code is Write it into the Viewcontroller, just write it directly, and the system will automatically call it.

Set the color style of the status bar:

//设置状态栏的颜色,返回的是一个枚举类型:
-(UIStatusBarStyle)preferredStatusBarStyle{
    return  UIStatusBarStyleDefault;
}
//枚举类型:
typedef NS_ENUM(NSInteger, UIStatusBarStyle) {
    UIStatusBarStyleDefault  = 0, // 根据用户设置,自动设置颜色模式
    UIStatusBarStyleLightContent = 1, // 显示白色状态栏,用于黑色背景
    UIStatusBarStyleDarkContent = 3, // 显示黑色状态栏,用于白色背景
} 

Set whether the status bar is hidden/shown:

//设置是否显示状态栏,return YES就会隐藏状态栏,return NO就会显示状态栏
-(BOOL)prefersStatusBarHidden{
    return YES;
}

Guess you like

Origin blog.csdn.net/JustinZYP/article/details/124259670