XLPagerTabStrip - 如何在选择更改时更改所选栏的颜色

Posted

技术标签:

【中文标题】XLPagerTabStrip - 如何在选择更改时更改所选栏的颜色【英文标题】:XLPagerTabStrip - How do I change the selected bar color as the selection changes 【发布时间】:2017-01-21 05:57:35 【问题描述】:

我正在尝试设计一个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       
   

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

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

【问题讨论】:

考虑为您的问题添加更多标签。 xlpagertabstrip有0个关注者 感谢您添加这些内容。我想,既然他们在他们的 github 上链接以在此处发布带有该标签的问题,那么他们正在关注它.. 嗯。也许,但仍然,整个网站上只有大约 23 个问题有这个标签 【参考方案1】:

代码检查

如果您检查代码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:

其实这不是问题。应在调用 viewDidLoad 之前配置设置。能否请您在自述文件中记录下来?

解决方法

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

【讨论】:

谢谢,我一定错过了那个帖子,因为我尝试查看 github 问题。完美运行,谢谢。 这应该写在文档中。拜托,Xmartlabs,你能更新你的文档吗?谢谢。 @Fox5150 你应该在 github repo 上为此打开一个问题

以上是关于XLPagerTabStrip - 如何在选择更改时更改所选栏的颜色的主要内容,如果未能解决你的问题,请参考以下文章

XLPagerTabStrip - 选定的选项卡选择不起作用

XLPagerTabStrip:不尊重状态栏

XLPagerTabStrip 选择首先显示的视图控制器

如何在 xlpagertabstrip 的 IndicatorInfo 中设置字符串?

如何使用 XLPagerTabStrip

XLPagerTabStrip 黑色空间