【发布时间】:2019-11-25 14:28:23
【问题描述】:
我有一个分段控件,我正在尝试更改分段标题的字体大小。我尝试了多个代码,但它不起作用。这就是我更改分段控件字体大小的方式:
let font = UIFont.systemFont(ofSize: 16)
segmentControl.setTitleTextAttributes([NSAttributedString.Key.font: font], for: .normal)
但是当我运行应用程序时,它并没有改变字体大小。 这是我在 viewDidLoad 中的所有代码:
let font = UIFont.systemFont(ofSize: 16)
segmentControl.setTitleTextAttributes([NSAttributedString.Key.font: font], for: .normal)
let titleTextAttributes = [NSAttributedString.Key.foregroundColor: UIColor.red]
segmentControl.setTitleTextAttributes(titleTextAttributes, for: .selected)
segmentControl.fallBackToPreIOS13Layout(using: UIColor.clear)
segmentControl.font(name: "Helvetica", size: 16)
let titleTextAttributesForSelected = [NSAttributedString.Key.foregroundColor: UIColor.white]
let titleTextAttributesForNormal = [NSAttributedString.Key.foregroundColor: UIColor.gray]
segmentControl.setTitleTextAttributes(titleTextAttributesForSelected, for: .selected)
segmentControl.setTitleTextAttributes(titleTextAttributesForNormal, for: .normal)
【问题讨论】: