kingston
kingston

Reputation: 1553

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

Upvotes: 1

Views: 3958

Answers (4)

HannahCarney
HannahCarney

Reputation: 3631

Go to your asset folder, find the asset and click on Identity Inspector. Change "Render As" to Original Image (assuming your icon is the color you want it).

Enter image description here

Upvotes: 2

NiKKi
NiKKi

Reputation: 3296

In the class where you define the tab bar set the property of the tabBarItem to ->>

UITabBarItem *tabBarItem1 = [[self.tabBar.tabBar items] objectAtIndex:0];
[tabBarItem1 setFinishedSelectedImage:[UIImage imageNamed:@"campaigns_hover.png"] withFinishedUnselectedImage:[UIImage imageNamed:@"campaigns.png"]];

It’s a property of tabBarItem and you can change the default blue image to a custom image. campaigns_hover.png is the selected custom image and campaigns.png is the custom image when not selected...

Enjoy the secret... :)

It does not use a private API... The function is defined under the UITabBarItem.h class.

Upvotes: 5

mark
mark

Reputation: 26

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.

Upvotes: 1

Amy Worrall
Amy Worrall

Reputation: 16337

Are you aware that the code you're trying to use uses private APIs and thus will cause your apps to be rejected?

I don't know about the specific error you're seeing. But if you're looking for another solution, one that'll make it into the App Store, you could try PESTabBarAdditions.

Upvotes: 1

Related Questions