我尝试使用以下iOS的自定义状态栏背景颜色显示不
UINavigationBar.appearance().tintColor = UIColor.orangeColor()
UINavigationBar.appearance().barTintColor = UIColor.orangeColor()
UINavigationBar.appearance().titleTextAttributes = [NSForegroundColorAttributeName: UIColor.whiteColor()]
UIApplication.sharedApplication().setStatusBarStyle(UIStatusBarStyle.LightContent, animated: true)
不过,我得到的是应该从以下充满橙色,而不是白色状态栏填满状态栏的背景颜色为橙色下面这个例子:Customize navigation bar appearance with swift
我在AppDelegate.swift下的文件didFinishLaunchingWithOptions设置此功能方法将它应用到整个应用程序。
我已经编辑我的的info.plist以下几点:View controller-based status bar appearance => NO
有谁知道我做错了吗?
编辑:我不知道,如果它的事项,但认为是在的UITabBarController
编辑2:这是在所有的意见发生实际上,不只是的UITabBarController。
编辑3:谢谢@Utsav帕瑞克
我添加视图现在状态栏的顶部,它短暂的瞬间,而应用程序加载状态栏是橙色的,但是,一旦它完成加载它被关闭视图并被替换为通用白色状态栏。 为什么会发生这种情况?
let view = UIView(frame: CGRect(x: 0.0, y: 0.0, width: UIScreen.mainScreen().bounds.size.width, height: 20.0))
view.backgroundColor=UIColor.orangeColor()
self.window!.rootViewController!.view.addSubview(view)
编辑为夫特3:
与的UITabBarController
let view = UIView(frame: CGRect(x: 0.0, y: 0.0, width: UIScreen.main.bounds.size.width, height: 20.0))
view.backgroundColor = .orange
self.view.addSubview(view)
没有嵌入式控制器
我知道有些人来这里不仅是状态栏,但实际上在导航栏上,让我学到了一些技巧,一起做没有任何嵌入式控制器的方式:
添加这个方法在你AppDelegate.swift并调用它在didFinishLaunchingWithOptions
func customizeAppearance() {
UINavigationBar.appearance().barTintColor = UIColor.black
UINavigationBar.appearance().titleTextAttributes = [NSForegroundColorAttributeName: UIColor.white]
UITabBar.appearance().barTintColor = UIColor.black
let tintColor = UIColor(red: 255/255.0, green: 255/255.0, blue: 255/255.0, alpha: 1.0)
UITabBar.appearance().tintColor = tintColor
}
访问这个链接...它可能有助于 [这里] [1] [1]:http://stackoverflow.com/questions/26956728/changing-the-status-bar-color- for-specific-viewcontrollers-using-swift-in-ios8 –
@AshokLondhe我在使用该链接之前询问了这个问题,但没有运气。 – Simon
更改常规 - >目标 - >状态栏样式下的状态栏样式。看看这是否有任何效果。也可以在应用程序委托启动后通过调度尝试更改外观,然后等待2秒 – TheCodingArt