Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

using default icons in UITabbar

Tags:

iphone

i am using tab bar control in my app and want to use the default search icon in one of my tab. I am making the tab bar programmically but i am not able to find a property where i can specify UITabBarSystemItemSearch item which i find in apple documentation. Following is my code for tab bar

CouponsViewController *coupons = [[CouponsViewController alloc] init];
    UINavigationController *couponsNavigationController = [[UINavigationController alloc] initWithRootViewController:coupons];
    couponsNavigationController.tabBarItem.title = @"Coupons";
    couponsNavigationController.navigationBar.tintColor = [UIColor colorWithRed:0.0 green:0.0 blue:0.0 alpha:0.1];
    [coupons release];

    SettingsViewController *settings = [[SettingsViewController alloc] init];
    UINavigationController *settingsNavigationController = [[UINavigationController alloc] initWithRootViewController:settings];
    settingsNavigationController.tabBarItem.title = @"Settings";
    settingsNavigationController.navigationBar.tintColor = [UIColor colorWithRed:0.0 green:0.0 blue:0.0 alpha:0.1];
    [settings release];

    ProfileViewController *profile = [[ProfileViewController alloc] init];
    UINavigationController *profileNavigationController = [[UINavigationController alloc] initWithRootViewController:profile];
    profileNavigationController.tabBarItem.title = @"Profile";
    profileNavigationController.tabBarItem.image = [UIImage imageNamed:@"profileImg.png"];
    profileNavigationController.navigationBar.tintColor = [UIColor colorWithRed:0.0 green:0.0 blue:0.0 alpha:0.1];
    [profile release];

    [tabBarController setViewControllers:[NSArray arrayWithObjects:loyaltyNavigationController,searchNavigationController,couponsNavigationController,settingsNavigationController,profileNavigationController,nil]  animated:NO];
    tabBarController.delegate=self;
    tabBarController.selectedIndex=0;

    [window addSubview:tabBarController.view];
like image 394
pankaj Avatar asked Dec 29 '22 20:12

pankaj


1 Answers

execute this code in your UIViewController subclass that you are putting into the tab bar. This is best done in your view controller's initializer method:

- (id) init
{
    self.title = @"search";
    self.tabBarItem = [[UITabBarItem alloc] initWithTabBarSystemItem:UITabBarSystemItemSearch
                                                                 tag:0];

    return self;
}  
like image 117
Mihir Mehta Avatar answered Jan 17 '23 14:01

Mihir Mehta