返回时不显示分段控件颜色,从视图中看第四个
segmented control color not showing when going back and fourth from view
我的分段控件在第一次加载时显示了我想要的紫色文本,但是当我按回导航栏然后返回视图时,颜色消失了。我已经在 viewDidLoad 和 viewWillAppear 中尝试过了。
override func viewDidLoad() {
mySegmentedControl.tintColor = UIColor.black
mySegmentedControl.setFontSize(fontSize: 14)
UISegmentedControl.appearance().setTitleTextAttributes([NSForegroundColorAttributeName: UIColor.purple], for: UIControlState.selected)
super.viewDidLoad()
}
我认为你应该为每个 UISegmentedControl
设置 setTitleTextAttributes
而不是为所有 UISegmentedControl
设置。
override func viewDidLoad() {
super.viewDidLoad()
mySegmentedControl.tintColor = UIColor.black
mySegmentedControl.setFontSize(fontSize: 14)
mySegmentedControl.setTitleTextAttributes([NSForegroundColorAttributeName: UIColor.purple], for: .selected)
}
我的分段控件在第一次加载时显示了我想要的紫色文本,但是当我按回导航栏然后返回视图时,颜色消失了。我已经在 viewDidLoad 和 viewWillAppear 中尝试过了。
override func viewDidLoad() {
mySegmentedControl.tintColor = UIColor.black
mySegmentedControl.setFontSize(fontSize: 14)
UISegmentedControl.appearance().setTitleTextAttributes([NSForegroundColorAttributeName: UIColor.purple], for: UIControlState.selected)
super.viewDidLoad()
}
我认为你应该为每个 UISegmentedControl
设置 setTitleTextAttributes
而不是为所有 UISegmentedControl
设置。
override func viewDidLoad() {
super.viewDidLoad()
mySegmentedControl.tintColor = UIColor.black
mySegmentedControl.setFontSize(fontSize: 14)
mySegmentedControl.setTitleTextAttributes([NSForegroundColorAttributeName: UIColor.purple], for: .selected)
}