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

标签 ios swift xlpagertabstrip

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

相关文章:

ios - ButtonBarPagerTabStripViewController updateIndicator toIndex 错误

c++ - 是否可以在 iOS 上编译为 Arduino 编写的代码?

ios - 如何避免类型丢失?

ios - Hashable == 方法无法快速检测两个对象之间的差异

ios - NWPathMonitor 在 Swift 中调用不满意

ios - XLPagerTabStrip:标题标签未显示在寻呼机选项卡上

ios - 使异步 alamofire 请求同步

ios - 如何在 Swift3 IOS 饼图中添加点击手势识别?

ios - 更改导航栏时平滑过渡 "prefersLargeTitles"

ios - XLPagerTabStrip:不尊重状态栏