【问题标题】:How to change tab bar item text colour on focus in TVOS如何在 TVOS 中更改焦点上的标签栏项目文本颜色
【发布时间】:2016-03-29 17:32:34
【问题描述】:

我在标签栏中有四个项目。

1> 观看。 (黑色)

2> 按需。 (黑色)

3> 搜索。 (黑色)

4> 设置。 (我的颜色)

如何更改标签栏中项目文本的颜色以匹配其图标颜色。 (现在在标签栏中选择了性能)

在此处输入图片说明

如何更改标签栏中“1,2,3”文本的颜色以匹配其图标颜色。 (现在在标签栏中选择了性能)

我尝试设置 TitleTextAttributes。

UITabBarItem.appearance().setTitleTextAttributes([NSForegroundColorAttributeName: UIColor(red: 255.0/255.0, green: 255.0/255.0, blue: 255.0/255.0, alpha: 1.0),NSFontAttributeName: UIFont(name: "SFUIDisplay-Regular", size: 36.0)!], forState:UIControlState.Normal)
UITabBarItem.appearance().setTitleTextAttributes([NSForegroundColorAttributeName: UIColor(red: 22.0/255.0, green: 209.0/255.0, blue: 237.0/255.0, alpha: 1.0),NSFontAttributeName: UIFont(name: "SFUIDisplay-Regular", size: 36.0)!], forState:UIControlState.Focused)

但我想喜欢它。

这个问题出现在 tvos 9.1 中。

【问题讨论】:

    标签: uitabbarcontroller uitabbar xcode7.2 swift5 tvos9.1


    【解决方案1】:

    我不确定我是否理解您的问题,但我在开发 Apple TV 应用时遇到了一些类似的问题。

    我想做的是改变标签栏项目的字体颜色。

    这就是我结束的工作。首先,我创建了一个UITabBarController 子类,并将其添加到故事板上的控制器中。 然后我在-(void)viewDidLoad中添加了这段代码

    for(UITabBarItem * item in self.tabBar.items) {
        [item setTitleTextAttributes:@{NSForegroundColorAttributeName : [UIColor darkGrayColor]} forState:UIControlStateNormal];
        [item setTitleTextAttributes:@{NSForegroundColorAttributeName : [UIColor blueColor]} forState:UIControlStateFocused];
    }
    

    一切运行良好。

    希望对你有帮助!

    【讨论】:

      【解决方案2】:

      swift 5解决方案:

      override func viewDidLoad() {
          super.viewDidLoad()
      
          for item in (self.tabBarController?.tabBar.items)! {
              item.setTitleTextAttributes([NSAttributedString.Key.foregroundColor: UIColor.white], for: .focused)
              item.setTitleTextAttributes([NSAttributedString.Key.foregroundColor: UIColor.lightGray], for: .normal)
          }
      }
      

      【讨论】:

        猜你喜欢
        • 2013-09-12
        • 1970-01-01
        • 2014-02-04
        • 2013-11-17
        • 2015-09-15
        • 2015-12-31
        • 1970-01-01
        • 2014-07-15
        • 1970-01-01
        相关资源
        最近更新 更多