Swift 5.0

Xcode  Version 11.4 (11E146)

Swift 5.0或OC项目

iOS13.0

1.png

升级最新的Xcode版本后,运行项目报错,发现报错原因是

//设置状态栏颜色

- (void)setStatusBarBackgroundColor:(UIColor *)color{} 

这个方法。

解决方法:

//设置状态栏颜色

- (void)setStatusBarBackgroundColor:(UIColor *)color {

    if(@available(iOS13.0, *)) {

        UIStatusBarManager *statusBarManager = [UIApplication sharedApplication].keyWindow.windowScene.statusBarManager;

        if([statusBarManagerrespondsToSelector:@selector(createLocalStatusBar)]) {

            UIView*localStatusBarView= [statusBarManager            performSelector:@selector(createLocalStatusBar)];

            UIView*statusBarView = [localStatusBarViewperformSelector:@selector(statusBar)];

           //根据当前状态栏的类型,重置状态栏颜色(否则截屏出来的都是默认颜色)

            UIColor*statusBarColor = color;

            UIStatusBarStyle statusBarStyle = self.preferredStatusBarStyle;//获取当前视图控制器的状态栏类型

            if(statusBarStyle ==UIStatusBarStyleLightContent) {

                [statusBarViewperformSelector:@selector(setForegroundColor:)withObject:statusBarColor];

            }

        }else{

            UIView *statusBar = [[[UIApplication sharedApplication] valueForKey:@"statusBarWindow"] valueForKey:@"statusBar"];

            if([statusBarrespondsToSelector:@selector(setBackgroundColor:)]) {

                statusBar.backgroundColor= color;

            }

        }

    }else{

    UIView *statusBar = [[[UIApplication sharedApplication] valueForKey:@"statusBarWindow"] valueForKey:@"statusBar"];

    if([statusBarrespondsToSelector:@selector(setBackgroundColor:)]) {

        statusBar.backgroundColor= color;

    }

    }

}

你可能感兴趣的:(Swift 5.0)