我正在尝试做一个设计 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
}
更改导航 Controller 的颜色有效,但我无法从此处更改所选栏(或设置对象下的任何内容)?
加载 View 后是否可以更改设置?
最佳答案
代码检查
如果你检查代码Code Search for 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 Issue #137 :
Actually this isnot a issue. Settings should be configured before viewDidLoad is called. Could you please document it in the readme?
解决方法
buttonBarView
是一个公共(public)变量,也许您可以将其设置为直接设置此属性:buttonBarView.selectedBar.backgroundColor
关于ios - XLPagerTabStrip - 如何在选择更改时更改所选栏的颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41776216/