ios – UISegmentedColor issue with text color and swipe (swift)

0
81

[ad_1]

I have a little issue with my segmented control. Sometimes when i swipe, the text color don’t change on the selected segmented. I don’t have this issue when i click to change segmented, only when i swipe.

Here, this is my code :

func setup() {
            segmented.selectedSegmentIndex = 0
            segmented.layer.backgroundColor = UIColor.background.cgColor
            segmented.border.width = 2
            segmented.border.color = .baseColor
    
    
            segmented.setTitleTextAttributes([NSAttributedString.Key.foregroundColor: UIColor.baseColor], for: .selected)
    
            segmented.setTitleTextAttributes([NSAttributedString.Key.foregroundColor: UIColor.baseColor], for: .normal)

            
            segmented.addTarget(self, action: #selector(switchView(_:)), for: .valueChanged)
}        


    @objc func switchView(_ sender: UISegmentedControl) {
            guard let views = self.views else { return }
            
            views[currentIndex].hide()
            currentIndex = sender.selectedSegmentIndex
            views[currentIndex].show()
    }    

segmented 1

segmented 2 works

segmented 3 fail

in advance, thank you

[ad_2]