gpt4 book ai didi

ios - (Swift) 选中的 tabBar 颜色?

转载 作者:搜寻专家 更新时间:2023-10-31 22:50:27 27 4
gpt4 key购买 nike

我已经知道如何设置 tabBar 的“barTintColor”。我想知道的是如何为选定的 tabBar 设置特定颜色(如图所示,选定的 tabBar 具有深粉色)。就像那样。提前致谢:)

Tab Bar

最佳答案

更改 tintColor(这是您可以做的所有事情)

创建 UITabBarController 的子类,将其设置为 UITabBarViewController 的类:

class myOwnTBC: UITabBarController {
override func viewDidLoad() {
super.viewDidLoad()
self.tabBar.tintColor = .blueColor()
}
}

根据您的评论进行更多研究后:

我确实相信,Apple 不希望开发人员更改 UITabBar 的背景颜色。请参阅 Apple 的 Interface Guidelines concerning the TabBar .我引用它:

A tab bar: Is translucent

我尝试子类化 UITabBarItem 并操作背景,这给了我以下异常:

Directly modifying a tab bar managed by a tab bar Controller is not allowed

解决方案?!你不会喜欢它,但如果你想使用 UITabBarController,你必须坚持使用半透明预设。

解决方法?目前我能想到的唯一解决方法是:使用您自己的 UIView 子类创建您自己的导航。这无论如何都会违反界面指南,但您可以实现您的目标。

关于ios - (Swift) 选中的 tabBar 颜色?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29998143/

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