0

I am developing an application that requires a scrolling UITabBarController. The customary 5 tab items max with the 5th being the More.. tab just won't do. I have found some pretty great third party classes such as https://github.com/Marxon13/M13InfiniteTabBar and they are great and have the functionality I would like but still, things aren't perfect. When I rotate my device to landscape things become glitchy.

Basically, I am fed up and want to create my own custom UITabBarController with scrolling..how would I go about doing this? I understand I would most likely put a UITabBar within UIScrollView but I am lost without a detailed tutorial of sorts..

Any help would be greatly appreciated! Thanks!!

rmaddy
  • 314,917
  • 42
  • 532
  • 579
Mike Simz
  • 3,976
  • 4
  • 26
  • 43

1 Answers1

1

The way I would approach this is to avoid modifying the UITabBar, since it is highly specialized, and create a UIViewController subclass that will provide this functionality for you. This view controller should have a container view (take a look at this Apple documentation for more detailed information) that will have each child view controller's content view.

For the actual tab bar itself, you have a few options depending on what you similar you want it to the standard UITabBar.

  1. You could have a super basic tab bar that consists of a UIScrollView with standard UIButtons that change/load the correct content view controller. Creating the tab bar would be then easy, simply add the buttons to the scroll view inside some type of loop (you could have the x positions be a multiple of the tab index to make positioning easier). UIButtons have support for a selected button state that you can use. You can change the scroll view's background.

  2. You could have a fancy tab bar which is constructed essentially like the above, but by having a custom UIButton subclass instead of a standard UIButton. This will allow you to implement a more intricate design (i.e. with and more customized touch handling.

Tips:

  • Use [myImage imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate] to have your tab images tinted like the standard tabs when selected.

  • Design the basics of your custom view controller in your storyboard. It is really easy to add the child container view and the scroll view this way.

Hope this helps!

zekel
  • 9,227
  • 10
  • 65
  • 96
sgonzalez
  • 1,086
  • 9
  • 24
  • thanks for the heads up! Okay so what I'm understanding is I have a custom view controller with a container view that will be the place where my table views controllers will be. Now my question is, how should I properly swap in and out the different table view controllers when the corresponding tab button is selected? @sgonzalez – Mike Simz Aug 13 '14 at 19:23
  • Yep. This post should have all the information you need: http://stackoverflow.com/questions/16330195/change-container-view-content-with-tabs-in-ios – sgonzalez Aug 13 '14 at 19:39
  • you my friend, are a damn beauty! @sgonzalez – Mike Simz Aug 13 '14 at 19:45
  • the link you posted is telling me that swapping view controllers in and out of a container view won't work..? @sgonzalez – Mike Simz Aug 14 '14 at 15:28
  • It does work. An easy way to do this is to connect the container in the storyboard to all the view controllers that you want. You can then use ```performSegueWithIdentifier:sender:``` for each tab. Take a look at this GitHub repo for relevant code (https://github.com/mhaddl/MHCustomTabBarController). – sgonzalez Aug 14 '14 at 17:31