[英]Changing the status bar text color in splash screen iOS 7
我知道已经有一些stackoverflow 问题说明了如何更改所有视图控制器的状态栏。 我目前正在以这种方式更改状态栏的颜色:
if(IS_IOS7)
[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent];
在application:DidFinishLaunching
另外,我已将plist中的UIViewControllerBasedStatusBarAppearance
的值更改为NO
。 但是,在启动画面中,它仍会显示带有黑色的状态栏文本。
是否可以在启动画面中更改状态栏文本颜色的颜色?
在项目plist文件中添加“状态栏样式”属性(键是UIStatusBarStyle
)。 然后忽略此属性的下拉列表中列出的所有可能值,并键入UIStatusBarStyleLightContent
。
并且您不必在plist中将UIViewControllerBasedStatusBarAppearance
设置为NO
,您可以将想要的preferredStatusBarStyle
设置为视图控制器。
您无需编写任何代码即可完成此操作
执行以下操作以使状态栏文本颜色在整个应用程序中变为白色
在你的项目plist文件:
UIStatusBarStyleLightContent
NO
NO
您可以执行以下操作以在整个应用程序中获取浅色状态栏。
在plist文件中添加以下值:
这将帮助您在整个应用程序中获取WHITE颜色的状态栏,包括SPLASH SCREEN。
在plist中将UIViewControllerBasedStatusBarAppearance
设置为No
然后在did finish launch选项中添加以下代码
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);
}
请按照此代码为我工作
以下是关于状态栏更改的Apple指南/说明 。
这是 - 如何更改状态栏样式:
如果要设置状态栏样式,应用程序级别,请在“.plist”文件中将UIViewControllerBasedStatusBarAppearance
设置为NO
。
如果您要在视图控制器级别设置状态栏样式,请按照下列步骤操作:
.plist
文件中将UIViewControllerBasedStatusBarAppearance
设置为YES
。 在viewDidLoad中添加函数setNeedsStatusBarAppearanceUpdate
覆盖视图控制器中的preferredStatusBarStyle。
-
override func viewDidLoad() {
super.viewDidLoad()
self.setNeedsStatusBarAppearanceUpdate()
}
override var preferredStatusBarStyle: UIStatusBarStyle {
return .lightContent
}
根据状态栏样式设置级别设置.plist的值。
您可以在应用程序启动期间或视图控制器的viewDidLoad期间为状态栏设置背景颜色。
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
}
}
结果如下:
您可以执行以下操作以在整个应用程序中获取浅色状态栏。
在项目导航器中选择项目的名称。 从项目编辑器左栏的列表中选择目标的名称。 单击项目编辑器顶部的“常规”。 设置状态栏样式 - >灯光
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.