XLPagerTabStrip 标签的屏幕宽度不相等:Swift

XLPagerTabStrip Tabs not getting equal width of screen :Swift

我正在使用 XLPagerTabStrip,我有一个 Scrollview 和一个 collectionView,名称分别为 Container 和 ButtonBarView。除了 Tab item Visibility 之外,一切正常。我想要 Tabs 之类的东西,等分标签。

父控制器代码为:

import UIKit
import XLPagerTabStrip

class ParentViewController: ButtonBarPagerTabStripViewController {

let purpleInspireColor = UIColor(red:0.13, green:0.03, blue:0.25, alpha:1.0)
override func viewDidLoad() {
    super.viewDidLoad()
    self.edgesForExtendedLayout = []

    // change selected bar color
    settings.style.buttonBarBackgroundColor = .white
    settings.style.buttonBarItemBackgroundColor = .white
    settings.style.selectedBarBackgroundColor = purpleInspireColor
    settings.style.buttonBarItemFont = .boldSystemFont(ofSize: 14)
    settings.style.selectedBarHeight = 2.0
    settings.style.buttonBarMinimumLineSpacing = 0
    settings.style.buttonBarItemTitleColor = .black
    settings.style.buttonBarItemsShouldFillAvailiableWidth = true
    settings.style.buttonBarLeftContentInset = 0
    settings.style.buttonBarRightContentInset = 0
    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 = self?.purpleInspireColor
    }

}


override func viewControllers(for pagerTabStripController: PagerTabStripViewController) -> [UIViewController] {
    let included = UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "IncludedViewController")
    let premium = UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "PremiumViewController")
    // let luxury = UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "LuxuryViewController")
    return [included,premium]
}
}

我有两个选项卡,分别名为 Included 和 Premium。

我找到了这个问题的答案

转到 Xcode 项目中的 pod 文件。将 UICollectionViewDelegate 更改为 UICollectionViewDelegateFlowLayout。

classButtonBarPagerTabStripViewController:PagerTabStripViewController、PagerTabStripDataSource、PagerTabStripIsProgressiveDelegate、UICollectionViewDataSource、UICollectionViewDelegateFlowLayout