Custom UITabBarController

I want to customize the look of the UITabBarController tab bar. I want to change the colors, how the icon looks when selected, and most importantly, I want to reduce the size of the custom toolbar.

My approaches to this and obstacles in it:

A) The first solution that came to my mind was to create my own viewController that will act like a UITabBarController with buttons at the bottom and add this viewController to the window. When the user clicks the button at the bottom, replace the view in scope with a new viewController that corresponds to the button the user is now using.

The problem with this strategy is this: since I change the view to the corresponding viewControllers will not receive these messages:

  • viewWillAppear

  • viewWillDisappear

  • viewDidAppear

  • viewDidDisappear

And all rotation events

B) I could use the accepted approach of the answer in this thread: Custom UITabBarController problems with controllers and view views

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

From the above reasons, I cannot use these approaches.

Having said that, I have no specific requirement for the Advanced tab. I will only have 5 tabs to show in the tab bar and hence the reordering of the tab bar items is out of scope.

Waiting for suggestions and ideas.

+1


source to share


2 answers


I've never tried something like this, but as I see you have to manually send these messages to the controllers of your child view.

No need to send -viewWill / Did (Dis). The correct controller will appear at the right time. This is what it does UITabBarController

.

As for rotation events:



  • In shouldAutorotateToInterfaceOrientation:

    forward this message to your child controllers and set the return value based on their return values ​​( UITabBarController

    only returns YES

    if all of its child controllers return YES

    for the requested orientation).

  • Forward willRotateToInterfaceOrientation:duration:

    , didRotateFromInterfaceOrientation:

    and willAnimateRotationToInterfaceOrientation:duration:

    child controllers (at least for the current view) when you receive them.

  • If you have configured the autoresistance masks of your child controllers correctly, they will rotate and resize correctly when the system rotates your custom tab bar controller view. (At least I think it should work.)

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

+2


source


You can implement the following code to create a custom tab bar used for images using CGRect make. Additional code is used to create a custom tab bar



-(void)applicationDidFinishLaunching:(UIApplication *)application {

    // Add the tab bar controller current view as a subview of the window
    tabBarController.delegate = self;
    tabBarController = [[UITabBarController alloc] init];

    mainDashBoard = [[DashBoard alloc] initWithNibName:@"DashBoard" bundle:nil];
    mainSearchView = [[SearchView alloc] initWithNibName:@"SearchView" bundle:nil];
    mainMoreView = [[MoreView alloc] initWithNibName:@"MoreView" bundle:nil];

    UINavigationController *nvCtr0 = [[[UINavigationController alloc] init] autorelease];
    UINavigationController *nvCtr1 = [[[UINavigationController alloc] initWithRootViewController:mainDashBoard] autorelease];
    UINavigationController *nvCtr2 = [[[UINavigationController alloc] initWithRootViewController:mainSearchView] autorelease];
    UINavigationController *nvCtr3 = [[[UINavigationController alloc] initWithRootViewController:mainMoreView] autorelease];
    UINavigationController *nvCtr4 = [[[UINavigationController alloc] init] autorelease];//[[[UINavigationController alloc] initWithRootViewController:nil] autorelease];

    tabBarController.viewControllers = [NSArray arrayWithObjects:nvCtr0,nvCtr1,nvCtr2,nvCtr3,nvCtr4,nil];

    nvCtr0.tabBarItem.enabled = NO;
    nvCtr4.tabBarItem.enabled = NO;

    [window tabBarController.view];
}

      

0


source







All Articles