The status bar color settings preferredStatusBarStyle

Ado direct teach you how to modify it

1, add categories category

5892667-44845fd08c83ea0f.png
image.png
#import <UIKit/UIKit.h>

NS_ASSUME_NONNULL_BEGIN

@interface UINavigationController (StatusBarStyle)

@end

NS_ASSUME_NONNULL_END




#import "UINavigationController+StatusBarStyle.h"

@implementation UINavigationController (StatusBarStyle)

- (UIViewController *)childViewControllerForStatusBarStyle {
    return self.visibleViewController;
}
- (UIViewController *)childViewControllerForStatusBarHidden {
    return self.visibleViewController;
}
@end

2, modify the info file


5892667-fe101108240efb92.png
image.png
key: Application requires iPhone environment  
value: YES

3, modify the color of a controller

重写这个,返回你想要的状态,也可以用全局变量来返回,我这里是只改一次,你如果想随时改变,
- (UIStatusBarStyle)preferredStatusBarStyle {
    return UIStatusBarStyleLightContent;
}

4, update status

    [self setNeedsStatusBarAppearanceUpdate];

Well, I think you have to modify successful
do not forget thumbs V_V

Reproduced in: https: //www.jianshu.com/p/3b7f6cf60432

Guess you like

Origin blog.csdn.net/weixin_34388207/article/details/91289564