Search code examples
objective-cxcode

Change tabbar icon color from default blue


I’m trying to change the tabbar icon color from default blue to red, but I’m getting this error:

Stray '\342' in program

I’m getting the error at "-(void)recolorItemsWithColor:......." and also at the implementation section. Is there a way to solve this error?

Is there another method to change the tab bar icon from default blue to some other color?

@interface UITabBar (ColorExtensions)

– (void)recolorItemsWithColor:(UIColor *)color shadowColor:(UIColor *)shadowColor shadowOffset:(CGSize)shadowOffset shadowBlur:(CGFloat)shadowBlur;

@end

Solution

  • Try adding a 49x49 png image into your project, then paste these line of code into your app delegate inside the applicationDidFinishLaunching and before adding a subview.

    CGRect frame = CGRectMake(0, 0, 480, 49);
    UIView *view = [[UIView alloc] initWithFrame:frame];
    UIImage *tabBarBackgroundImage = [UIImage imageNamed:@"49x49.png"];
    UIColor *color = [[UIColor alloc] initWithPatternImage:tabBarBackgroundImage];
    
    [view setBackgroundColor:color];
    [color release];
    [[tabcontroller tabBar] insertSubview:view atIndex:0];
    [view release];
    

    Hope it will help.