我的分段控件显示了第一次加载时我想要的紫色文本,但是当我按回导航栏然后返回到视图时,颜色消失了。我在viewDidLoad和viewWillAppear中尝试过它。
override func viewDidLoad() {
mySegmentedControl.tintColor = UIColor.black
mySegmentedControl.setFontSize(fontSize: 14)
UISegmentedControl.appearance().setTitleTextAttributes([NSForegroundColorAttributeName: UIColor.purple], for: UIControlState.selected)
super.viewDidLoad()
}
答案 0 :(得分:0)
我认为您应为每个setTitleTextAttributes
设置UISegmentedControl
,而不是为所有UISegmentedControl
设置。
override func viewDidLoad() {
super.viewDidLoad()
mySegmentedControl.tintColor = UIColor.black
mySegmentedControl.setFontSize(fontSize: 14)
mySegmentedControl.setTitleTextAttributes([NSForegroundColorAttributeName: UIColor.purple], for: .selected)
}