码农的世界

iOS设置状态栏背景颜色

2019-10-17  本文已影响0人  EvenCode

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

}

上一篇下一篇

猜你喜欢

热点阅读