1

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
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
kingston
  • 1,553
  • 4
  • 22
  • 42
  • "`Stray '\342' in program`" is not enough for identification, but it is the signature for UTF-8 sequences. The one in the provided source is Unicode code point U+2013 ([EN DASH](https://www.utf8-chartable.de/unicode-utf8-table.pl?start=8192&number=128)), UTF-8 sequence 0xE2 0x80 0x93, 342 200 223 (octal). Thus the triplet "`Stray '\342' in program. Stray '\200' in program. Stray '\223' in program.`" is expected. – Peter Mortensen Apr 30 '23 at 02:27
  • Does this answer your question? [Compilation error: stray ‘\302’ in program, etc](https://stackoverflow.com/questions/19198332/compilation-error-stray-302-in-program-etc) – Peter Mortensen Apr 30 '23 at 02:29
  • The "stray" error is a ***very*** common error when copying code from web pages, [PDF](https://en.wikipedia.org/wiki/Portable_Document_Format) documents, through chat (e.g. [Skype Chat](https://en.wikipedia.org/wiki/Features_of_Skype#Skype_chat) or [Facebook Messenger](https://en.wikipedia.org/wiki/Facebook_Messenger)), etc. The canonical question is *[Compilation error: stray ‘\302’ in program, etc.](https://stackoverflow.com/questions/19198332)*. – Peter Mortensen Apr 30 '23 at 02:35

4 Answers4

5

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.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
NiKKi
  • 3,296
  • 3
  • 29
  • 39
  • it works. but it doesn't work first time. when i select tab after that it shows the original color of tab icon. any help? – Imran Ahmed Mar 12 '15 at 06:12
2

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

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
HannahCarney
  • 3,441
  • 2
  • 26
  • 32
  • How does this answer the question? This seems like a completely bogus answer. – Peter Mortensen Apr 30 '23 at 02:35
  • Not bogus, just ensure your png is the color you want it, and it won't be blue -I prefer non programmatic answers. There is a lot you can do in identity inspector, but also this was 5 years ago. – HannahCarney May 08 '23 at 09:19
1

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.

Amy Worrall
  • 16,250
  • 3
  • 42
  • 65
1

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.

mark
  • 26
  • 1