UISegementedControl 字体大小

UISegementedControl font size

我正在尝试更改 tvOS 中 UISegementedControl 的字体大小(如果有帮助的话)。默认情况下,字体很大!我已经能够像这样减少它

let switchAttributes = [NSForegroundColorAttributeName: UIColor.lightGray, NSFontAttributeName: UIFont.systemFont(ofSize: 28)]
segementedControl.setTitleTextAttributes(switchAttributes, for: .normal)

但这似乎只影响它的 .normal 状态。所有其他州似乎都不受此影响,也不受指定其文本属性的影响:

segementedControl.setTitleTextAttributes(switchAttributes, for: .selected) // No effect
segementedControl.setTitleTextAttributes(switchAttributes, for: .focused) // No effect

在这里你可以看到focused和selected状态有多大

我知道之前已经回答过这个问题并且我的代码之前工作正常,但是自从 tvOS 10 更新以来一切都坏了,我还没有找到解决这个问题的方法。也许这只是 Apple 的错误,但也许我遗漏了什么?

感谢任何帮助。

试试这个:

let font = UIFont.boldSystemFont(ofSize: 8.0)
let attributes = [ NSFontAttributeName : font ]
segmentedControl.setTitleTextAttributes(attributes, for: .selected)

当我测试它时对我有用