我有UIToolbar
(在我的里面UINavigationController
)上面有一些UIBarButtonItem
s。
工具栏是blue
( isTranslucent = false
),按钮是white
。默认高亮颜色是gray
,看起来很难看。
我找到的唯一解决方案是更改UIBarButtonItem
's tintColor
in @IBAction
touch 事件。但是我有很多UIBarButtonItem
s 并且在每个@IBAction
.
你知道如何全局改变它,或者至少是子类UIBarButtonItem
来定义它一次并在任何地方使用这个类吗?
我使用 swift 3,部署目标是 iOS 9+
您didFinishLaunchingWithOptions
的AppDelegate
女巫中有您的函数,它告诉委托启动过程几乎完成并且应用程序几乎可以运行了。
在那里你可以appearance
在你的UIBarButtonItem
和UINavigationBar
.
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
// Text
UIBarButtonItem.appearance().setTitleTextAttributes([NSForegroundColorAttributeName: UIColor.green], for: .normal)
UIBarButtonItem.appearance().setTitleTextAttributes([NSForegroundColorAttributeName: UIColor.darkGray], for: .selected)
// Images
UINavigationBar.appearance().tintColor = UIColor.orange
return true
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句