美文网首页码农的世界
iOS设置状态栏背景颜色

iOS设置状态栏背景颜色

作者: EvenCode | 来源:发表于2019-10-17 09:48 被阅读0次

Objective C

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

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

    if([statusBar respondsToSelector:@selector(setBackgroundColor:)]) 

    { statusBar.backgroundColor = color; 

    }

}

Swift

func setStatusBarBackgroundColor(color:UIColor) { 

    guard let statusBar =UIApplication.sharedApplication().valueForKey("statusBarWindow")?.valueForKey("statusBar") as?UIView

    else{

        return

    } 

    statusBar.backgroundColor = color

}

相关文章