我正在尝试配置UISegmentedController
该类的一个实例,以便我可以将未选择段中的文本颜色从默认的黑色设置为两段分段控制器的白色。但我找不到任何方法。我尝试使用该setTitleTextAttributes(_,for:)
方法,但找不到合适的NSAttributedString.Key
属性来更改文本颜色。
user7142686
问问题
17 次
1 回答
0
这在操场上对我有用:
import UIKit
import PlaygroundSupport
let seg = UISegmentedControl(items: ["foo", "bar"])
seg.setTitleTextAttributes([.foregroundColor: UIColor.red], for: .normal)
seg.setTitleTextAttributes([.foregroundColor: UIColor.blue], for: .selected)
seg.selectedSegmentIndex = 0
PlaygroundPage.current.liveView = seg
于 2020-04-29T13:58:03.920 回答