views:

78

answers:

1

Hi All,

I want to customize the look and feel of the tab bar of a UITabBarController. I want to change the colors, the way the icon looks when they are selected, and also, most important of all, I want to reduce the size of the custom toolbar.

My approaches for this and the hurdles in it are:

A) The first solution which came to my mind was to create my own viewController which will act like a UITabBarController with buttons in the bottom and add this viewController to the window. Once when user taps a button at the bottom, swap the view in the viewable area with the new viewController's which corresponds to the button now tapped by user.

The problem with this strategy is: since I swap view's the corresponding viewControllers will not get these messages:

-viewWillAppear
-viewWillDisappear
-viewDidAppear
-viewDidDisappear

And all the rotation events

B) I could have used the accepted answer's approach in this thread: http://stackoverflow.com/questions/1432992/custom-uitabbarcontroller-problems-with-view-controllers-and-views

But my tabBar's height is not the same as the default.

Due to the cited reasons above, I cannot use those approaches.

Having said this, I have no special requirement of More tab. I will be having only 5 tabs which will be displayed by the tab bar and hence the re-ordering of tab bar items is out of scope.

Awaiting suggestions and ideas.

Thanks, Raj

+2  A: 

I have never attempted something like this but as I see it, you are supposed to send those messages to your child view controllers manually.

It shouldn't be problem to send -viewWill/Did(Dis)Appear to the right controller at the appropriate moment. This is what UITabBarController does, too.

As for rotation events:

  • In shouldAutorotateToInterfaceOrientation:, forward this message to your child controllers and set your return value depending on their return values (UITabBarController only returns YES if all its child controllers return YES for the requested orientation).

  • Forward willRotateToInterfaceOrientation:duration:, didRotateFromInterfaceOrientation: and willAnimateRotationToInterfaceOrientation:duration: to the child controllers (at least to the currently visible one) when you receive them.

  • If you have set the autoresizing masks of your child controllers' views correctly, they you rotate and resize correctly when the system rotates your custom tab bar controller's view. (At least I think that's how it should work.)

Again, I'm not sure if this will work.

Ole Begemann
Hmmm, thanx for your suggestion. Well I could customize as you have said. Also, I can forward all the messages just as you have cited. But the concerns are: 1. -viewWillAppear and disAppear will be nothing but a consecutive set of calls! 2. The view controller automatically gets initial orientation call back when the view is loaded viz. -didRotateFromInterfaceOrientation, but in this case we will have to simulate it. 3. I am concerned about any problems or hurdles that might arise in the future, since this is the base for my app I wonder if this risk is worth taking?
Raj
All the view controllers in this sentence means: "UITabBarController only returns YES if all its child controllers return YES for the requested orientation", say if there are 4 tabs, then if all the viewcontrollers corresponding to 4 tabs respond to current orientation only then it should return YES -OR- only the view controller which is displayed by the TabBarcontroller should be queried for?
Raj