Segment title color changes when I get back from another tab
AndreiBoariu opened this issue · comments
Andy Boariu commented
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)
])
Any idea how to fix that ?
Thanks
Yonat Sharon commented
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
Andy Boariu commented
@yonat I already tried, and seems is working fine.
Thanks for your quick help!