Изменить цвет заголовка элемента управления сегментом при переключении сегмента в Swift ⇐ IOS
-
Anonymous
Изменить цвет заголовка элемента управления сегментом при переключении сегмента в Swift
У меня есть контроллер представления, на котором у меня есть управление сегментами, и я переключаю сегменты жестом пролистывания, теперь я хочу, чтобы при переключении сегментов цвет заголовка текущего сегмента становился белым, а оставшийся цвет - серым, я искал об этом но я получил результаты по изменению цвета фона, как я могу изменить цвет заголовка элемента управления сегментом при переключении между сегментами? Это мой код для сегмента при пролистывании
let titleTextAttributes = [NSAttributedString.Key.foregroundColor: UIColor.red] сегментControl.setTitleTextAttributes(titleTextAttributes, for: .selected) сегментControl.fallBackToPreIOS13Layout (с использованием: UIColor.clear) let swipeRight = UISwipeGestureRecouncer(target: self, action: #selector(self.swipedRight)) swipeRight.direction = UISwipeGestureRecouncer.Direction.right self.activeView.addGestureRecouncer(swipeRight) let swipeLeft = UISwipeGestureRecouncer(target: self, action: #selector(self.swipedLeft)) swipeLeft.direction = UISwipeGestureRecouncer.Direction.left self.closedView.addGestureRecouncer(swipeLeft) @objc func swipedRight(){ сегментControl.selectedSegmentIndex = 0 self.activeView.isHidden = ложь self.closedView.isHidden = правда пусть titleTextAttributes = [NSAttributedString.Key.foregroundColor: UIColor.white] сегментControl.setTitleTextAttributes(titleTextAttributes, for: .selected) пусть titleText = [NSAttributedString.Key.foregroundColor: UIColor.gray] сегментControl.setTitleTextAttributes(titleText, for: .disabled) getActiveQuestionAPI() } @objc func swipedLeft(){ сегментControl.selectedSegmentIndex = 1 self.activeView.isHidden = правда self.closedView.isHidden = ложь пусть titleTextAttributes = [NSAttributedString.Key.foregroundColor: UIColor.white] сегментControl.setTitleTextAttributes(titleTextAttributes, for: .selected) пусть titleText = [NSAttributedString.Key.foregroundColor: UIColor.gray] сегментControl.setTitleTextAttributes(titleText, for: .disabled) getCloseQuestionAPI() }
У меня есть контроллер представления, на котором у меня есть управление сегментами, и я переключаю сегменты жестом пролистывания, теперь я хочу, чтобы при переключении сегментов цвет заголовка текущего сегмента становился белым, а оставшийся цвет - серым, я искал об этом но я получил результаты по изменению цвета фона, как я могу изменить цвет заголовка элемента управления сегментом при переключении между сегментами? Это мой код для сегмента при пролистывании
let titleTextAttributes = [NSAttributedString.Key.foregroundColor: UIColor.red] сегментControl.setTitleTextAttributes(titleTextAttributes, for: .selected) сегментControl.fallBackToPreIOS13Layout (с использованием: UIColor.clear) let swipeRight = UISwipeGestureRecouncer(target: self, action: #selector(self.swipedRight)) swipeRight.direction = UISwipeGestureRecouncer.Direction.right self.activeView.addGestureRecouncer(swipeRight) let swipeLeft = UISwipeGestureRecouncer(target: self, action: #selector(self.swipedLeft)) swipeLeft.direction = UISwipeGestureRecouncer.Direction.left self.closedView.addGestureRecouncer(swipeLeft) @objc func swipedRight(){ сегментControl.selectedSegmentIndex = 0 self.activeView.isHidden = ложь self.closedView.isHidden = правда пусть titleTextAttributes = [NSAttributedString.Key.foregroundColor: UIColor.white] сегментControl.setTitleTextAttributes(titleTextAttributes, for: .selected) пусть titleText = [NSAttributedString.Key.foregroundColor: UIColor.gray] сегментControl.setTitleTextAttributes(titleText, for: .disabled) getActiveQuestionAPI() } @objc func swipedLeft(){ сегментControl.selectedSegmentIndex = 1 self.activeView.isHidden = правда self.closedView.isHidden = ложь пусть titleTextAttributes = [NSAttributedString.Key.foregroundColor: UIColor.white] сегментControl.setTitleTextAttributes(titleTextAttributes, for: .selected) пусть titleText = [NSAttributedString.Key.foregroundColor: UIColor.gray] сегментControl.setTitleTextAttributes(titleText, for: .disabled) getCloseQuestionAPI() }
Мобильная версия