更改状态栏颜色Objective-C
问题描述:
在我的应用程序中,有一个黑暗模式,我想知道如何更改状态栏的颜色? 谢谢,更改状态栏颜色Objective-C
UIColor *color = [UIColor whiteColor];
self.navigationController.navigationBar.barTintColor = color;
答
可以低于在AppDelegate.m
在didFinishLaunchingWithOptions
方法的代码行可能有助于:
[application setStatusBarHidden:NO];
[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent];
UIView *statusBar = [[[UIApplication sharedApplication] valueForKey:@"statusBarWindow"] valueForKey:@"statusBar"];
if ([statusBar respondsToSelector:@selector(setBackgroundColor:)]) {
statusBar.backgroundColor = [UIColor whiteColor];//set whatever color you like
}
答
夫特3溶液:
在需要非默认状态栏外观视图控制器,使用这个:
override var preferredStatusBarStyle: UIStatusBarStyle {
return .lightContent
}
答
一个简单而有效的方法是将属性添加到info.plist
并将状态栏样式设置为UIStatusBarStyleLightContent
。
我们应该做的是:
- 首先打开
info.plist
文件的应用程序,然后添加属性UIViewControllerBasedStatusBarAppearance
,并将其值设置为NO
-
下一页头到您
Appdelegate
或任何类别文件并使用以下代码:UIApplication.sharedApplication.statusBarStyle = UIStatusBarStyleLightContent;
另一种编写代码的方法是:
[[UIApplication sharedApplication] setStatusBarStyle: UIStatusBarStyleLightContent];
不这样做,这是一个黑客,可能让你的应用程序被拒绝使用私有的API就像一个魅力 – Dvole
工作 –