2

I want to add a little flair to my application and while I have been somewhat successful, I haven't figured out a way to truly do what I want to do. I would try to subclass UITabViewController, but I don't think I would even know where to start or if that is the right approach.

Basically, what I want to do is have custom images for each tab bar button. I have both pressed and non-pressed images. Instead of using the highlight that is generated over the current icon, I want the pressed image to be shown. What I've been able to do is create a Category of the UITabBar with a custom drawRect method that basically draws all of my custom tab bar icons. I then initialize the same amount of UITabBarItems w/out specifying an image or title of any kind which I then add to the array of items. This lets me have my icons and then just overlays the highlight on them.

This is ok I guess, but I would really like to have the pressed button look.

Here is the code I use for drawing the tab bar:

@implementation UITabBar (CustomImage)


-(void)drawRect:(CGRect)rect
{
    UIImage *image = [UIImage imageNamed:@"TabBar.png"];
    [image drawInRect:CGRectMake(0,0,320,50)];
}

@end

And then I initialize the tab bar items like this:

UITabBarItem *homeTabBarItem = [[UITabBarItem alloc] init];

If anyone knows how I would do this, that would be greatly appreciated. Please keep in mind that I'm still relatively new to Objective-C, so I'm somewhat confused as to how I would correctly subclass anything at this point.

The functionality I'm looking for would be similar to what RougeSheep was able to accomplish with Postage: http://postage.roguesheep.com/ They did an awesome job, and this is kind of what I'd like to emulate.

TheAggie
  • 57
  • 1
  • 10
  • Were you able to make any progress with this? – barfoon Nov 01 '10 at 14:04
  • 1
    Yeah. The solution isn't very pretty though. You would probably be better off writing your own TabBarController class from scratch. Regardless, the simple answer is I subclassed UIViewController which acts as my main view controller. Contained within this view controller is an "internal" UITabBarController and a custom tab bar view controller which I throw on top of it. The trick is that in order to hide the original tab bar you have to push navigation controllers onto it which hide the bottom toolbar. There is a lot more too it than that though, and I'm running out of space. – TheAggie Nov 05 '10 at 19:12
  • Maybe you could answer your own answer ? – Goles Sep 26 '11 at 07:32

0 Answers0