分段控制颜色在返回时不显示,从视图返回第四

时间:2017-04-14 02:46:52

标签: ios swift uisegmentedcontrol viewdidload

我的分段控件显示了第一次加载时我想要的紫色文本,但是当我按回导航栏然后返回到视图时,颜色消失了。我在viewDidLoad和viewWillAppear中尝试过它。

   override func viewDidLoad() {

    mySegmentedControl.tintColor = UIColor.black
    mySegmentedControl.setFontSize(fontSize: 14)

    UISegmentedControl.appearance().setTitleTextAttributes([NSForegroundColorAttributeName: UIColor.purple], for: UIControlState.selected)

    super.viewDidLoad()


}

1 个答案:

答案 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)
}