0

I am trying to use XLPagerTabStrip to switch between view controllers, but my app has a status bar at the top and I want to move the tab-strip below the status bar, but I can't seem to do that. I found another similar question that said to connect a container view to the PagerTabStripViewController, but when I try that I get an error in the module's code:

let fromFrame = layoutAttributesForItem(at: IndexPath(item: fromIndex, section: 0))!.frame //Thread 1: Fatal error: Unexpectedly found nil while unwrapping an Optional value

Here is my code:

class NewsTabController: ButtonBarPagerTabStripViewController {

    @IBOutlet weak var barView: ButtonBarView!

    @IBOutlet weak var imageView: UIImageView!

    override func viewDidLoad() {
        super.viewDidLoad()

        let margins = view.layoutMarginsGuide

        imageView.topAnchor.constraint(equalTo: margins.topAnchor, constant: 5).isActive = true
        imageView.widthAnchor.constraint(equalToConstant: 35).isActive = true
        imageView.heightAnchor.constraint(equalToConstant: 35).isActive = true
        imageView.centerXAnchor.constraint(equalTo: margins.centerXAnchor).isActive = true

        self.buttonBarView = barView
        barView.topAnchor.constraint(equalTo: imageView.bottomAnchor).isActive = true
        barView.leftAnchor.constraint(equalTo: view.leftAnchor).isActive = true
        barView.rightAnchor.constraint(equalTo: view.rightAnchor).isActive = true
        barView.heightAnchor.constraint(equalToConstant: 30).isActive = true

    }

    override func viewControllers(for pagerTabStripController: PagerTabStripViewController) -> [UIViewController] {
        let child1 = storyboard!.instantiateViewController(identifier: "WebVC")
        return [child1]
    }

    func loadDesign(){
        self.settings.style.selectedBarHeight = 1
        self.settings.style.selectedBarBackgroundColor = .lightGray
        self.settings.style.buttonBarBackgroundColor = Constants.darkPurple
        self.settings.style.buttonBarItemBackgroundColor = .black
        self.settings.style.buttonBarItemFont = .systemFont(ofSize: 13)
        self.settings.style.selectedBarHeight = 4.0
        self.settings.style.buttonBarMinimumLineSpacing = 0
        self.settings.style.buttonBarItemTitleColor = .white
        self.settings.style.buttonBarItemsShouldFillAvailableWidth = true
        self.settings.style.buttonBarLeftContentInset = 10
        self.settings.style.buttonBarRightContentInset = 10



        changeCurrentIndexProgressive = {(oldCell: ButtonBarViewCell?,newCell:ButtonBarViewCell?,progressPercentage:CGFloat,changeCurrentIndex:Bool,animated:Bool) -> Void in
            guard changeCurrentIndex == true else {return}
            oldCell?.label.textColor = .white
            newCell?.label.textColor = .white
        }
    }

}
fisch
  • 106
  • 7

0 Answers0