XLPagerTabStrip - 如何在选择更改时更改所选栏的颜色
XLPagerTabStrip - How do I change the selected bar color as the selection changes
我正在尝试设计一个 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
}
更改导航控制器的颜色有效,但我无法从此处更改所选栏(或设置对象下的任何内容)?
加载视图后是否可以更改设置?
代码检查
如果您查看代码 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
我正在尝试设计一个 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
}
更改导航控制器的颜色有效,但我无法从此处更改所选栏(或设置对象下的任何内容)?
加载视图后是否可以更改设置?
代码检查
如果您查看代码 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