我嘗試使用以下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