XLPagerTabStrip不会填满整个宽度

dav*_*hor 2 ios swift xlpagertabstrip

问题

我正在研究IOS应用程序.我使用XLPagerTabStrip库来创建像Android一样的标签.YouTube上.一切正常,但我有Tabs的问题.

我有3个标签,但他们不会填写整个宽度,他们自己重叠.

有问题的3个选项卡


Paren级代码

import UIKit
import XLPagerTabStrip

class InformationsParentView: ButtonBarPagerTabStripViewController {

    let purpleInspireColor = UIColor(red:0.13, green:0.03, blue:0.25, alpha:1.0)

    override func viewDidLoad() {

        super.viewDidLoad()

        settings.style.buttonBarBackgroundColor = .white
        settings.style.buttonBarItemBackgroundColor = .white
        settings.style.selectedBarBackgroundColor = purpleInspireColor
        settings.style.buttonBarItemLeftRightMargin = 0
        settings.style.selectedBarHeight = 2
        settings.style.buttonBarMinimumLineSpacing = 20
        settings.style.buttonBarItemTitleColor = .black
        settings.style.buttonBarItemLeftRightMargin = 0
        settings.style.buttonBarItemsShouldFillAvailiableWidth = true
    }

    override func viewControllers(for pagerTabStripController: PagerTabStripViewController) -> [UIViewController] {
        let tabWorkers = UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "sbWorkers")
        let tabPLs = UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "sbPLs")
        let tabSuperiors = UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "sbSuperiors")

        return [tabWorkers, tabPLs, tabSuperiors]
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }

}
Run Code Online (Sandbox Code Playgroud)

故事板

现场

现场

现场

现场

属性检查员

属性检查员

大小检查员

大小检查员


相关信息

我找到了一个解决方案,但它对我不起作用(Github Issue 256):

settings.style.buttonBarItemsShouldFillAvailableWidth = true除非我另外指定settings.style.buttonBarItemLeftRightMargin = 0,否则不会为我填充可用的宽度.

有人有解决方案吗?

我正在使用XCode版本9,Swift 3和IOS 11.

小智 6

在pod中打开ButtonBarPagerTabStripViewController.swift文件.

ButtonBarPagerTabStripViewController类定义中,删除UICollectionViewDelegate协议并实现UICollectionViewDelegateFlowLayout协议.

所以改变源代码

open class ButtonBarPagerTabStripViewController: 
    PagerTabStripViewController, PagerTabStripDataSource, 
    PagerTabStripIsProgressiveDelegate, UICollectionViewDelegate, 
    UICollectionViewDataSource {
        ...
}
Run Code Online (Sandbox Code Playgroud)

open class ButtonBarPagerTabStripViewController: 
    PagerTabStripViewController, PagerTabStripDataSource, 
    PagerTabStripIsProgressiveDelegate, UICollectionViewDataSource, 
    UICollectionViewDelegateFlowLayout {
        ...
}
Run Code Online (Sandbox Code Playgroud)

当我将我的应用程序从XCode 8.3.3迁移到XCode 9时,我遇到了这个问题.这是pod的问题.如果您使用XCode 8.3.3进行尝试,您将看到没有错误.如果要使用XCode 9,请执行上述方法.