iosswiftxlpagertabstrip

XLPagerTabStrip doesn't fill full width


Problem

I'm working on an IOS Application. I use XLPagerTabStrip Library to create Tabs like in Android eg. YouTube. Everything works fine but i have a problem with the Tabs.

I have 3 Tabs but they wont fill out the whole width and they are overlapping themselves.

3 Tabs with the Problem


Paren-Class Code

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

Scene

Scene

Attributes Inspector

Attributes Inspector

Size Inspector

Size Inspector


Infos

I have found a solution but it didn't work for me (Github Issue 256):

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

Has anyone a solution for this?

I'm working with XCode Version 9, Swift 3 and IOS 11.


Solution

  • Open ButtonBarPagerTabStripViewController.swift file in the pod.

    In ButtonBarPagerTabStripViewController class definition, remove UICollectionViewDelegate protocol and implement UICollectionViewDelegateFlowLayout protocol.

    So change source code

    from

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

    to

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

    I've met that problem when I migrated my app from XCode 8.3.3 to XCode 9. It's pod's problem. If you try it with XCode 8.3.3, you will see no bugs. If you want to use XCode 9, do the above method.