Search code examples
iphoneobjective-ciosuitabbarcontrolleruitabbar

I'm trying to customize a UITabbar using the following code without any luck


I'm trying to customize a UITabbar using the following code without any luck:

this is in my viewDidLoad method

 UIImage *tabBackground = [[UIImage imageNamed:@"tabbar.png"]
                              resizableImageWithCapInsets:UIEdgeInsetsMake(0, 0, 0, 0)];
    // Set background for all UITabBars
    [[UITabBar appearance] setBackgroundImage:tabBackground];
    // Set background for only this UITabBar
    [[self.tabBarController tabBar] setBackgroundImage:tabBackground];

any idea where I might be going wrong here? thanks


Solution

  • We can change the background color of UITabBar controller. Please refer the code which is given below.Hope this helps you.

       tabBar1.backgroundColor = [UIColor clearColor];
       CGRect frame = CGRectMake(0, 0, 480, 49);
       UIView *view = [[UIView alloc] initWithFrame:frame];
       UIImage *image = [UIImage imageNamed:@"Image.png"];
       UIColor *color = [[UIColor alloc] initWithPatternImage:image];
       view.backgroundColor = color;
       [color release];
       [[self tabBar] insertSubview:view atIndex:0];
       [view release];