swift - UISegementedControl字体大小

标签 swift uisegmentedcontrol tvos

我正在尝试更改 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

enter image description here

在这里您可以看到重点状态和选定状态有多大

我知道这个问题之前已经得到了解答,并且我的代码之前工作得很好,但自从 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/

相关文章:

ios - UISegmentedController 在 collectionview 和 tableview 之间切换

ios - 如何从 AVAsset 或 AVPlayerItem 获取主 list 中的所有 HLS 变体?

ios - 关于 App 布局的 TVOS(如 iTunes 等)

ios - 如何改变 UISegmentedControl 的颜色?我的色调不显示

swift - 多个回调而不是在 swift 中使用委托(delegate)

arrays - 在 Swift 中向可选数组添加元素

SwiftUI - DragGesture 和 .onDelete 冲突

iphone - UISegmentedControl 最佳实践

swift - TVOS - ScrollView 内的 UICollectionView - ScrollView 不滚动

swift - 发送者的不同定义