gpt4 book ai didi

ios - 选中或突出显示时全局更改 UIBarButtonItem 文本颜色

转载 作者:搜寻专家 更新时间:2023-11-01 05:52:19 24 4
gpt4 key购买 nike

我有 UIToolbar(在我的 UINavigationController 中),上面有一些 UIBarButtonItem

工具栏是蓝色(isTranslucent = false),按钮是白色。默认高亮颜色是灰色,看起来很难看。

我找到的唯一解决方案是在 @IBAction 触摸事件中更改 UIBarButtonItemtintColor。但是我有很多 UIBarButtonItem,在每个 @IBAction 中编写大量代码非常烦人。

您知道如何全局更改它,或者至少将 UIBarButtonItem 子类化以定义一次并在所有地方使用该类吗?

我使用 swift 3,部署目标是 iOS 9+

最佳答案

您的 AppDelegate 中有您的 didFinishLaunchingWithOptions 函数,它告诉委托(delegate)人启动过程即将完成,应用几乎可以运行了。

您可以在 UIBarButtonItemUINavigationBar 上使用 appearance

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
}

结果:
enter image description here

关于ios - 选中或突出显示时全局更改 UIBarButtonItem 文本颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45962080/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com