1
votes

I've created UITabBar (items: info, location and description) in the middle of the content and now i want to set custom background image for tab bar, default select first button and get action when user select another tab bar item.

Here is ss of tab bar: http://dl.dropbox.com/u/77033905/tabBar%20in%20the%20middle.png

Tell me pls answers on this questions:

  1. How to set custom background image for thisd tab bar?
  2. How to get selected item?
  3. How to default selected first item?

For now I've created UITabBar and include in this ViewController, what's next?

This is ViewController.h:

@interface ViewController : UIViewController<UITabBarDelegate> {
    UITabBar *tabBar;
}
@property (strong, nonatomic) IBOutlet UITabBar *tabBar;
...

View.m:

#import "ViewController.h"

@interface ViewController ()

@end

@implementation OfferViewController

@synthesize tabBar;
- (void)viewDidLoad
{
    [super viewDidLoad];

    UIImage *selectedImage0 = [UIImage imageNamed:@"HomeDB.png"];
    UIImage *unselectedImage0 = [UIImage imageNamed:@"HomeLB.png"];

    UIImage *selectedImage1 = [UIImage imageNamed:@"ScheduleDB.png"];
    UIImage *unselectedImage1 = [UIImage imageNamed:@"ScheduleLB.png"];

    UIImage *selectedImage2 = [UIImage imageNamed:@"BuildingsDB.png"];
    UIImage *unselectedImage2 = [UIImage imageNamed:@"BuildingsLB.png"];


    //UITabBar *tabBar = self.tabBar;
    UITabBarItem *item0 = [tabBar.items objectAtIndex:0];
    UITabBarItem *item1 = [tabBar.items objectAtIndex:1];
    UITabBarItem *item2 = [tabBar.items objectAtIndex:2];


    [item0 setFinishedSelectedImage:selectedImage0 withFinishedUnselectedImage:unselectedImage0];
    [item1 setFinishedSelectedImage:selectedImage1 withFinishedUnselectedImage:unselectedImage1];
    [item2 setFinishedSelectedImage:selectedImage2 withFinishedUnselectedImage:unselectedImage2];

    [super viewDidLoad];
}
...

How can I now default select item and get when user tabs on some tab bar item?

2

2 Answers

2
votes

this is the link which i have used for : custom tabbar

i hope this helps you ..

0
votes

Step 5 from link @iremk gave you is what you have to do to customize your tabbar, even if it's not controlled by the AppDelegate : as long as you have a reference on it in your viewController or whatever, you can use methods/properties of UITabBar class.

By The way, if by 'customizing' you just mean set your icons on items, and keeping the gray style of the tab bar, you could just set the Image property of your items in InterfaceBuilder.

For steps 2 and 3, just have a look on the UITabBar and UITabBarDelegate documentation :