let navStyles = UINavigationBar.appearance()
// This will set the color of the text for the back buttons.
navStyles.tintColor = .white
// This will set the background color for navBar
navStyles.barTintColor = .black
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
// Override point for customization after application launch.
let navigationBarAppearace = UINavigationBar.appearance()
navigationBarAppearace.tintColor = UIColor.whiteColor() // Back buttons and such
navigationBarAppearace.barTintColor = UIColor.purpleColor() // Bar's background color
navigationBarAppearace.titleTextAttributes = [NSForegroundColorAttributeName:UIColor.whiteColor()] // Title's text color
self.window?.backgroundColor = UIColor.whiteColor()
return true
}
var navigationBarAppearace = UINavigationBar.appearance()
navigationBarAppearace.tintColor = uicolorFromHex(0xffffff) // White color
navigationBarAppearace.barTintColor = uicolorFromHex(0x034517) // Green shade
// change navigation item title color
navigationBarAppearace.titleTextAttributes =[NSForegroundColorAttributeName:UIColor.whiteColor()]
22 回答
你应该用这个:
你有一个选择隐藏你的后退按钮,并与你自己 . 然后设置它的颜色 .
我这样做了:
对于Swift 2.0,要在AppDelegate.swift中使用以下内容更改 Navigation-bar tint color , title text 和 back button 色调更改
它将通过 - (void)viewDidLoad中的这一行解决:
在
didFinishLaunchingWithOptions
中,在didFinishLaunchingWithOptions
内使用此代码 .如果您已经在“设置”视图控制器中有后退按钮,并且您想要将“付款信息”视图控制器上的后退按钮颜色更改为其他内容,则可以在“设置”视图中执行此操作控制器准备这样的segue :
这适用于我,iOS 9.0
这个片段带来了魔力 . 而不是redColor,将其更改为您的愿望 .
在Swift 4中,您可以使用以下方法处理此问题:
设置
UINavigationBar.appearance().tintColor
的所有答案都与UIAppearance.h
中的Apple文档冲突 .在Xcode中,您需要按命令单击要与外观代理一起使用的每个属性,以检查头文件并确保使用
UI_APPEARANCE_SELECTOR
注释该属性 .因此,通过外观代理为整个应用程序着色导航栏紫色以及 Headers 和按钮白色的正确方法是:
请注意
UIBarButtonItem
不是UIView
的子类,而是NSObject
. 所以它的tintColor
属性不是UIView
的继承tintColor
.不幸的是,
UIBarButtonItem.tintColor
没有用UI_APPEARANCE_SELECTOR
注释 - 但在我看来这是一个文档错误 . Apple Engineering在this radar的回应表明它得到了支持 .Swift 4.2
Change complete app theme
Change specific controller
在 Swift3 中,将“后退”按钮设置为
red
.你可以像这样使用 . 把它放在
AppDelegate.swift
里面 .斯威夫特3
让我们试试这段代码:
在swift 2.0中使用
不知道为什么没有人提到过这个...但我正在做我在_146425中所做的事......而且它没有用 . 然后我将我的代码放入 viewWillAppear ,这一切都奏效了 .
上面的解决方案是更改单个barbuttonItem . 如果要更改代码中每个navigationBar的颜色,请遵循this answer .
基本上使用
appearance()
更改类本身就像在应用程序中对该视图的所有实例进行全局更改 . 欲了解更多,请参阅here您可以通过单击电路板上的空白区域并在右侧工具栏中选择“显示文件检查器”来更改故事板中的全局色调颜色,您将在工具栏的底部看到“全局色调”选项 .
此代码更改箭头颜色
如果这不起作用,请使用以下代码:
Swift 3 Notes
UIColor.whiteColor()
和类似已被简化为UIColor.white
此外,许多以前隐式的选项已更改为显式,因此您可能需要:
在故事板中很容易设置:
在 AppDelegate.swift 中将以下代码添加到 didFinishLaunchingWithOptions 函数
Swift 3
对于Swift 3,最受欢迎的答案是不正确的 .
更改颜色的正确代码是:
如果要更改颜色,请将上面的UIColor.white更改为所需的颜色