Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I create my own UITabBar? [closed]

Further to this question here, I'm really interested in creating my own UITabBar, and 'rolling my own'. Im really curious as to how this is done, especially in an app such as the Twitter app.

How can I do this? Can anyone point to any good resources on how to subclass this? Should I do it programmatically, or in a XIB?

Edit: I'm looking to do this with custom icons/selected icons and having icons only. Edit2: After reading further answers, it sounds like a custom XXTabBarcontroller is what I actually want to do here. Can anyone comment on this?

Thank you,

like image 733
barfoon Avatar asked Oct 26 '10 01:10

barfoon


4 Answers

I don't know if there is a best way to do this, but I will share my experience:

I created my own version of a tab bar by subclassing UIView as opposed to UITabBar. As the linked question mentions, Apple's UI classes are quite finicky about their sizing and I do not think I could get the UITabBar subclass to size as I wanted.

Because I did not have a subclass of UITabBar I also ended up rolling my own versions of UITabBarController and UITabBarDelegate, with interfaces that are essentially the same as the Apple classes. I WAS able to use UITabBarItem to store the title and icon for the buttons on the tab bar, which is useful since UIViewControllers have a tabBarItem property. That lets you store just an array of UIViewControllers in your controller, as opposed to arrays for both controllers and tab bar items.

Because I was using mostly custom classes I did this all programmatically, including creating, configuring and laying out the buttons on the tab bar.

Like I said, this is just my experience, hope it helps.

like image 193
Tim Isganitis Avatar answered Nov 11 '22 19:11

Tim Isganitis


I did this recently in an application. There was so little "code" to it that there is barely anything to post. I did it as such:

Created a UIImageView (about 50 px high), and laid it out at the bottom of the screen. I filled it with a tab-bar look-alike image - i.e. some sort of grey gradient. I probably subclassed UIImageView - but you don't even have to do that.

I drew a bunch of buttons/icons - 37x37 each.

I placed a bunch of UIButtons in the "tab bar" - and made them "Custom" views, with the buttons/icons I had created.

I simply used the touchUpInside methods to make them do stuff.

When I needed to get fancy - I'd attach the buttons to my code via and IBOutlet, so I could "disable" them - and I'd draw a greyish "disabled state" image for them.

like image 37
Brad Avatar answered Nov 11 '22 20:11

Brad


If you want the same functionality, I'd recommend using a UITabBarController, hide the tab bar itself, and then create your own navigation. I've done this a few times and it works quite nicely.

Use something like this to hide your tab bar and expand the content view.

- (void)makeTabBarHidden:(BOOL)hide
{
    if ( [tabBarController_.view.subviews count] < 2 )
        return;
    UIView *contentView;
    if ( [[tabBarController_.view.subviews objectAtIndex:0] isKindOfClass:[UITabBar class]] )
        contentView = [tabBarController_.view.subviews objectAtIndex:1];
    else
        contentView = [tabBarController_.view.subviews objectAtIndex:0];
    if (hide)
    {
        contentView.frame = tabBarController_.view.bounds;      
    }
    else
    {
        contentView.frame = CGRectMake(tabBarController_.view.bounds.origin.x,
                                       tabBarController_.view.bounds.origin.y,
                                       tabBarController_.view.bounds.size.width,
                                       tabBarController_.view.bounds.size.height - tabBarController_.tabBar.frame.size.height);
    }
    tabBarController_.tabBar.hidden = hide;
}

Then make your own navigation with UIButtons to switch between your view controllers.

[tabBarController_ setSelectedIndex:0];

like image 44
Brandon Schlenker Avatar answered Nov 11 '22 19:11

Brandon Schlenker


I think this is what you are looking for... should be pretty easy to subclass it. gl and cheer!

http://www.rumexit.co.uk/2010/07/how-to-customise-the-tab-bar-uitabbar-in-an-iphone-application-part-1-of-2/

like image 2
Unikorn Avatar answered Nov 11 '22 20:11

Unikorn