yonat / MultiSelectSegmentedControl

UISegmentedControl remake that supports selecting multiple segments, vertical stacking, combining text and images.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Segment title color changes when I get back from another tab

AndreiBoariu opened this issue · comments

You did a great work! Thanks @yonat

I am using this segment in a tab bar controller app, and place it on navigation item title view, and it looks brilliant.
But when I came back from another tab, title color changes back to black, or selected tab!

guard let navigationBar = navigationController?.navigationBar else { return }
		
let segmentedController = MultiSelectSegmentedControl()
segmentedController.items = ["Ask Away", "Contacts"]
segmentedController.setTitleTextAttributes([NSAttributedString.Key.foregroundColor: UIColor.white], for: .selected)
segmentedController.allowsMultipleSelection = false
segmentedController.selectedSegmentIndex = 0
segmentedController.delegate = self
segmentedController.tintColor = .askAwayColor()
segmentedController.borderWidth = 1
segmentedController.borderRadius = 4
navigationItem.titleView = segmentedController
		
NSLayoutConstraint.activate([
	segmentedController.topAnchor.constraint(equalTo: navigationBar.topAnchor, constant: 7),
	segmentedController.heightAnchor.constraint(equalToConstant: 30),
	segmentedController.widthAnchor.constraint(equalToConstant: 220),
	segmentedController.centerXAnchor.constraint(equalTo: navigationBar.centerXAnchor)
])

Here is a short description

Any idea how to fix that ?
Thanks

Will take a look tomorrow or later, but in the meanwhile, try changing:

segmentedController.setTitleTextAttributes([NSAttributedString.Key.foregroundColor: UIColor.white], for: .selected)

to this:

segmentedController.backgroundgroundColor = .white

@yonat I already tried, and seems is working fine.
Thanks for your quick help!