我正在尝试更改 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
在这里您可以看到重点状态和选定状态有多大
我知道这个问题之前已经得到了解答,并且我的代码之前工作得很好,但自从 tvOS 10 更新后,一切都崩溃了,我还没有找到任何方法来解决这个问题。也许这只是苹果的错误,但也许我错过了一些东西?
感谢任何帮助。
最佳答案
试试这个:
let font = UIFont.boldSystemFont(ofSize: 8.0)
let attributes = [ NSFontAttributeName : font ]
segmentedControl.setTitleTextAttributes(attributes, for: .selected)
当我测试它时为我工作
关于swift - UISegementedControl字体大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40005931/