ios - XLPagerTabStrip 不填满整个宽度

标签 ios swift xlpagertabstrip

问题

我正在开发 IOS 应用程序。 我使用 XLPagerTabStrip 库来创建像在 Android 中一样的标签。 YouTube。 一切正常,但我的选项卡有问题。

我有 3 个标签,但它们不会填满整个宽度,而且它们自己重叠。

3 Tabs with the Problem


父类代码

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.
    }

}

Storyboard

Scene

场景

Scene

场景

Attributes Inspector

属性检查器

Size Inspector

尺寸检查器


信息

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

settings.style.buttonBarItemsShouldFillAvailableWidth = true wouldn't fill the available width for me unless I specified settings.style.buttonBarItemLeftRightMargin = 0 as well.

有人解决这个问题吗?

我正在使用 XCode 版本 9、Swift 3 和 IOS 11。

最佳答案

打开 pod 中的 ButtonBarPagerTabStripViewController.swift 文件。

ButtonBarPagerTabStripViewController 类定义中,删除 UICollectionViewDelegate 协议(protocol)并实现 UICollectionViewDelegateFlowLayout 协议(protocol)。

所以改源码

来自

open class ButtonBarPagerTabStripViewController: 
    PagerTabStripViewController, PagerTabStripDataSource, 
    PagerTabStripIsProgressiveDelegate, UICollectionViewDelegate, 
    UICollectionViewDataSource {
        ...
}

open class ButtonBarPagerTabStripViewController: 
    PagerTabStripViewController, PagerTabStripDataSource, 
    PagerTabStripIsProgressiveDelegate, UICollectionViewDataSource, 
    UICollectionViewDelegateFlowLayout {
        ...
}

当我将我的应用程序从 XCode 8.3.3 迁移到 XCode 9 时,我遇到了这个问题。这是 pod 的问题。如果您尝试使用 XCode 8.3.3,您将看不到任何错误。如果你想使用 XCode 9,请执行上述方法。

关于ios - XLPagerTabStrip 不填满整个宽度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46400715/

相关文章:

ios - Paypal MPL iOS 错误

ios - OpenGL ES 2.0 绘制不显示任何内容的简单三角形

swift - Swift 中字符串常量的字符串格式化程序?

ios - XLPagerTabStrip 按钮栏宽度比导航栏宽

ios - XLPagerTabStrip 之间的空白

ios - 在最新的 xcode 5 中分别添加到 Storyboard 中的 UIViewController 后看不到 UIView

ios - Swift:JSON 似乎没问题,但我仍然收到 Cocoa 错误 3840

ios - RealmSwift (0.92.3) 和配置文件错误

ios - 如何确保我的数组结构在 Objective-C 和 Swift 中相同?

ios - 如何在 swift 中从 childViewContoller 刷新 parentViewContoller?