簡體   English   中英

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中的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也許您可以在直接設置此屬性的設置之外對其進行設置: buttonBarView.selectedBar.backgroundColor

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM