如何在tvOS 13中更改标签的背景颜色?

问题描述 投票:0回答:1

enter image description here TvOS 13.我有一个带有选项卡的UITabBarController。并且可以自定义几乎所有东西,除了以下明显的东西:焦点选项卡的背景。总是白色的。Guide告诉

为选定和未选定的项目指定色彩

我尝试过:

view.backgroundColor = .purple
tabBar.tintColor = .yellow
tabBar.barTintColor = .red
tabBar.unselectedItemTintColor = .brown
tabBar.backgroundColor = .green
tabBar.backgroundImage = UIColor.blue.toImage()
tabBar.shadowImage = UIColor.orange.toImage()
tabBar.selectionIndicatorImage = UIColor.burgundy.toImage()

无济于事。

uitabbarcontroller uitabbar tvos uitabbaritem tvos13
1个回答
0
投票

对于@davidv和其他人,这是我的解决方案:

extension UIView {
    func subviews<T:UIView>(ofType type: T.Type) -> [T] {
        var result = self.subviews.compactMap { $0 as? T }
        for sub in self.subviews {
            result.append(contentsOf: sub.subviews(ofType: type))
        }
        return result
    }
}

extension UIViewController {
    override func tabBar(_ tabBar: UITabBar, didSelect item: UITabBarItem) {
        // перекраска кнопки
        let allSubviews = tabBar.subviews(ofType: UIView.self)
        let whiteSubviews = allSubviews.filter { $0.backgroundColor == .white }
        for s in whiteSubviews {
            s.backgroundColor = .gold
        }
    }
}
© www.soinside.com 2019 - 2024. All rights reserved.