简体   繁体   中英

change tabbar icon color from default blue

im trying to change the tabbar icon color from default blue to red...im getting this error "Stray '\\342'in program".. im getting the error at "-(void)recolorItemsWithColor:......." and also at the implementation section...is der anyway to solve dis error...is there anyother 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

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"]];

Its a property of tabBarItem and u 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 uses a private API.. The function is defined under UITabBarItem.h class.

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

在此处输入图片说明

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 .

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM