1

I'm using YALFoldingTabBar for a project https://github.com/Yalantis/FoldingTabBar.iOS

I want to change its behavior a bit, by showing the current ViewController as the centerButtonImage, instead of a plus/cross sign.

I've tried to override didSelectItem like this:

   override func tabBar(tabBar: UITabBar, didSelectItem item: UITabBarItem!) {

    switch(self.selectedIndex)
    {
    case 0:
        self.centerButtonImage = UIImage(named: "whatever")
    default:
        //Change image
    }

    switch (self.selectedViewController)
    {
    case 0 as GameViewController:
        //Change image
    default:
        //Change image
    }
}

The code below is in my CustomTabBar, subclassing YALFoldingTabBarController.

But it doesn't seem to work that way. I've also tried to manipulate the tabBar in the specific UIViewControllers's viewDidLoad or viewDidAppear but it seems like the tabBar is set only.

Is this possible, and if so, what am I doing wrong?

EDIT: It seems like the method is not called, when changing viewController.

Mattias
  • 415
  • 3
  • 13

1 Answers1

0

I never got didSelectItem to work, and neither the UITabBarControllerDelegate´s equivalent. However, YALFoldingTabBar have delegate methods tabBarViewWillExpand and tabBarViewWillCollapse and I used these along with tabBarView.layoutSubviews() to solve my problem. It's not very beautiful, but works as intended.

func tabBarViewWillExpand(tabBarView: YALFoldingTabBar!) {

    self.centerButtonImage = UIImage(named: "plus_icon")
    //Helper method from other thread, link below
    performBlock({ () -> Void in
        tabBarView.layoutSubviews()
    }, afterDelay: 0.25)
}

How do you trigger a block after a delay, like -performSelector:withObject:afterDelay:?

Community
  • 1
  • 1
Mattias
  • 415
  • 3
  • 13