美文网首页iOS自我学习库ios开发
iOS设置状态栏背景颜色

iOS设置状态栏背景颜色

作者: iOS_Developer | 来源:发表于2016-09-29 18:51 被阅读1263次

参考:http://stackoverflow.com/questions/19063365/how-to-change-the-status-bar-background-color-and-text-color-on-ios-7
Objective C

- (void)setStatusBarBackgroundColor:(UIColor *)color { 
UIView *statusBar = [[[UIApplication sharedApplication] 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
}

相关文章