更改启动屏幕iOS 7中的状态栏文本颜色
我知道已经有人说如何更改所有视图控制器的状态栏。我目前正在以这种方式更改状态栏的颜色:更改启动屏幕iOS 7中的状态栏文本颜色,ios,ios7,splash-screen,statusbar,uistatusbar,Ios,Ios7,Splash Screen,Statusbar,Uistatusbar,我知道已经有人说如何更改所有视图控制器的状态栏。我目前正在以这种方式更改状态栏的颜色: if(IS_IOS7) [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent]; 在应用程序中:DidFinishLaunching 此外,我已将plist中的UIViewControllerBasedStatusBarAppearance的值更改为NO。但是,在splashscreen中,
if(IS_IOS7)
[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent];
在应用程序中:DidFinishLaunching
此外,我已将plist中的UIViewControllerBasedStatusBarAppearance
的值更改为NO
。但是,在splashscreen中,它仍然以黑色显示状态栏文本
是否可以更改启动屏幕中状态栏文本颜色?在项目plist文件中添加“状态栏样式”属性(键为
UIStatusBarStyle
)。然后忽略此属性下拉列表中列出的所有可能值,改为键入UIStatusBarStyleLightContent
您不必在plist中将
UIViewControllerBasedStatusBarAppearance
设置为NO
,您可以将视图控制器所需的preferredStatusBarStyle
设置为NO。在plist中将UIViewControllerBasedStatusBarAppearance
设置为NO
然后在“完成启动”选项中添加以下代码
if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7) {
[application setStatusBarStyle:UIStatusBarStyleLightContent];
self.window.clipsToBounds =YES;
self.window.frame = CGRectMake(0,20,self.window.frame.size.width,self.window.frame.size.height-20);
}
请遵循这条代码,它对我很有用您无需编写任何代码就可以做到这一点
执行以下操作,使状态栏文本在整个应用程序中变为白色 在您的项目plist上文件:
- 状态栏样式:
UIStatusBarStyleLightContent
- 查看基于控制器的状态栏外观:
NO
- 状态栏最初是隐藏的:
NO
这将帮助您在整个应用程序(包括启动屏幕)中获得白色的状态栏。您可以通过以下操作在整个应用程序中获得浅色状态栏 在项目导航器中选择项目的名称。 从项目编辑器左列的列表中选择目标的名称。 单击项目编辑器顶部的“常规”。 设置状态栏样式->灯光这里是关于状态栏更改的 以下是-如何更改状态栏样式: 如果要设置状态栏样式,请在应用程序级别将“.plist”文件中的
UIViewControllerBasedStatusBarAppearance
设置为NO
如果要在视图控制器级别设置状态栏样式,请执行以下步骤:
.plist
文件中将UIViewControllerBasedStatusBarAppearance
设置为YES
李>
SetNeedssStatusBarAppearanceUpdate
extension UIApplication {
var statusBarView: UIView? {
return value(forKey: "statusBar") as? UIView
}
}
// Set upon application launch, if you've application based status bar
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
UIApplication.shared.statusBarView?.backgroundColor = UIColor.red
return true
}
}
or
// Set it from your view controller if you've view controller based statusbar
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
UIApplication.shared.statusBarView?.backgroundColor = UIColor.red
}
}
-
根据状态栏样式设置级别设置.plist的值。
您可以在应用程序启动或视图控制器的ViewDid加载期间为状态栏设置背景色
extension UIApplication {
var statusBarView: UIView? {
return value(forKey: "statusBar") as? UIView
}
}
// Set upon application launch, if you've application based status bar
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
UIApplication.shared.statusBarView?.backgroundColor = UIColor.red
return true
}
}
or
// Set it from your view controller if you've view controller based statusbar
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
UIApplication.shared.statusBarView?.backgroundColor = UIColor.red
}
}
结果如下:
什么是“它仍然以黑色显示状态栏”:如果代码正常,状态栏字体应为白色,状态栏背景色取决于您的启动图像(现在应包括状态栏高度-20像素)。对不起,我真的错过了文本字。我只更改状态栏的文本颜色。我可以在启动屏幕出现后更改它,但在启动屏幕出现时无法更改。这是在状态栏上显示白色文本,而我的背景也很亮。如何在目标上显示黑色文本Mangesh转到常规设置那里你可以选择设置状态栏样式你可以使用点语法将第一行写得稍微简单一点,如:
if(UIDevice.currentDevice.systemVersion.floatValue>=7){
有没有办法让它与iOS 6上的着色状态栏兼容?状态栏的文本颜色可以是白色,也可以是黑色。状态栏的背景来自您的启动图像,如果它延伸到条下,则来自viewController的视图。经过大量不同的方法,这一方法终于奏效了(将UIViewControllerBasedStatusBarAppearance设置为“否”)。您是英雄。您也可以通过代码UIApplication.sharedApplication()执行此操作。statusBarStyle=.LightContent。我在中执行此操作AppDelegate@Yasmin:要在启动屏幕后更改颜色,此解决方案已经是问题的一部分;)被接受的答案是好的,但是如果不执行上面的第二个项目,它在我的所有视图控制器上都不起作用。谢谢!“基于视图控制器的状态栏外观:是
”似乎仍然起作用(iOS 9)