Monday, February 3, 2014

Customized Tab Bar

Web Hosting


In this tutorial I will show you how to customized tab bar. In your AppDelegate.m file, add this code below.

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    // Override point for customization after application launch.
    
    //customized tab bar
    UITabBarController *tabBarController = (UITabBarController *)self.window.rootViewController;
    UITabBar *tabBar = tabBarController.tabBar;
    UITabBarItem *tabBarItem1 = [tabBar.items objectAtIndex:0];
    UITabBarItem *tabBarItem2 = [tabBar.items objectAtIndex:1];
    
    tabBarItem1.title = @"Send Money";
    tabBarItem2.title = @"Rates";
    
    [tabBarItem1 setFinishedSelectedImage:[UIImage imageNamed:@"tabitem_selected.png"] withFinishedUnselectedImage:[UIImage imageNamed:@"tabitem_default.png"]];
    [tabBarItem2 setFinishedSelectedImage:[UIImage imageNamed:@"ratestab_selected.png"] withFinishedUnselectedImage:[UIImage imageNamed:@"ratestab_default.png"]];
    
    UIImage *tabBarBackground = [UIImage imageNamed:@"tabbar_bg.png"];
    [[UITabBar appearance] setBackgroundImage:tabBarBackground];
    [[UITabBar appearance] setSelectionIndicatorImage:[UIImage imageNamed:@"tabbar_item.png"]];
    
    [[UITabBarItem appearance] setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[UIColor whiteColor], UITextAttributeTextColor, nil] forState:UIControlStateNormal];
    
    UIColor *titleHighlightedColor = [UIColor colorWithRed:153/255.0 green:192/255.0 blue:48/255.0 alpha:1.0];
    [[UITabBarItem appearance] setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:titleHighlightedColor, UITextAttributeTextColor, nil] forState:UIControlStateHighlighted];
    end customizing tabBar
    
    
    return YES;

}



Web Hosting

That's it. Hope this tutorial help you.

No comments:

Post a Comment