Reputation: 313
I am trying to change the color of the text of tabbar item,programmatically. I am using
[[UITabBar appearance] setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:
[UIFont fontWithName:@"AmericanTypewriter" size:20.0f], UITextAttributeFont,
[UIColor blackColor], UITextAttributeTextColor,
[UIColor grayColor], UITextAttributeTextShadowColor,
[NSValue valueWithUIOffset:UIOffsetMake(0.0f, 1.0f)], UITextAttributeTextShadowOffset,
nil]];
Which should works on iOS5 and above. But my apps gets crashed with error at console :
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[_UIAppearance setTitleTextAttributes:]: unrecognized selector sent to instance 0x79f5790'
*** First throw call stack:
Not sure, why i am getting a crash. Also please suggest, if there is any other way to change the font color of the tabbar items.
Thanks
Upvotes: 0
Views: 512
Reputation: 696
Neither of these answers are correct (at least for iOS 6).
You're missing forState:
at the end of the call.
Example
[[UITabBarItem appearance] setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:
[UIColor whiteColor], UITextAttributeTextColor,
[UIColor grayColor], UITextAttributeTextShadowColor,
[NSValue valueWithUIOffset:UIOffsetMake(0.0f, 1.0f)], UITextAttributeTextShadowOffset,
nil] forState:UIControlStateNormal];
Upvotes: 2
Reputation: 12787
setTitleTextAttributes
is the method of UIBarItem
class.
so fetch tab bar items and set their title attributes.
see this
for setting styles in tab bar
Upvotes: 1
Reputation: 69479
The title in not part of the UITabBar
but UITabBarItem
thus replace UITabBar
:
[[UITabBarItem appearance] setTitleTextAttributes:
Upvotes: 1