2

我正在尝试设计一个XLPagerTabStrip控件,其中整体主题随着选项卡的变化而变化。

以下是选项卡更改时调用的内容

changeCurrentIndexProgressive = { [weak self] (oldCell: ButtonBarViewCell?, newCell: ButtonBarViewCell?, progressPercentage: CGFloat, changeCurrentIndex: Bool, animated: Bool) -> Void in
        guard changeCurrentIndex == true else { return }
        oldCell?.label.textColor = .black
        newCell?.label.textColor = UIColor.red

        //Change the navigation bar's color
        self?.navigationController?.navigationBar.barTintColor = UIColor.red

        //Attempting to change the selected bar color
        self?.settings.style.selectedBarBackgroundColor = UIColor.green       
   }

更改导航控制器颜色有效,但我无法从此处更改所选栏(或设置对象下的任何内容)?

加载视图后是否可以更改设置?

4

1 回答 1

6

代码检查

如果您检查selectedBarBackgroundColor 的代码代码搜索,那么您会发现这 3 个有趣的搜索结果:

BaseButtonBarPagerTabStripViewController#viewDidLoad

buttonBarView.selectedBar.backgroundColor = settings.style.selectedBarBackgroundColor

BarPagerTabStripViewController#viewDidLoad

barView.selectedBar.backgroundColor = settings.style.selectedBarBackgroundColor ?? barView.selectedBar.backgroundColor

ButtonBarPagerTabStripViewController#viewDidLoad

buttonBarView.selectedBar.backgroundColor = settings.style.selectedBarBackgroundColor

这意味着您需要在 viewDidLoad 之前设置 BackgroundColor。

问题

另请参阅此问题的答案:XLPagerTabStrip 问题 #137

其实这不是问题。应在调用 viewDidLoad 之前配置设置。你能把它记录在自述文件中吗?

解决方法

buttonBarView是一个公共变量,也许您可​​以将其设置为直接此属性的设置:buttonBarView.selectedBar.backgroundColor

于 2017-01-21T07:26:03.257 回答