开发者

Custom UITabBarController

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:

And all the rotation events

B) I could have used the accepted answer's approach in this thread: 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.


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.


You can implement the following code for the creating the custom tab bar in that use to images using the CGRect make.further code is use for the creating the custom tab bar

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

    // Add the tab bar controller's 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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜