更改标签栏文字颜色,iPhone
我已经编程创build了一个tabbar。
我们可以改变标签栏的标题颜色吗? 默认是白色的,即时通讯设法使它变黑。
就像是
tabbaritem.text.textcolor=[UIcolor Blackcolor];
谢谢
在iOS5中,您使用外观代理来更改标题颜色:
对于特定的tabbar项目:
[[UITabBarItem appearance] setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys: [UIFont fontWithName:@"AmericanTypewriter" size:20.0f], UITextAttributeFont, [UIColor yellowColor], UITextAttributeTextColor, [UIColor redColor], UITextAttributeTextShadowColor, [NSValue valueWithUIOffset:UIOffsetMake(0.0f, 1.0f)], UITextAttributeTextShadowOffset, nil] forState:UIControlStateNormal];
或用[UITabBarItem appearance]
replaceself.tabBarItem
更改所有的标签栏项目。 如果你想改变它们,我build议你把代码放在appdelegate didFinishLaunchingWithOptions:
只是别的…
在iOS 5中设置标准外观:
在你的AppDelegate.m中做:
[[UITabBar appearance] setTintColor:myColor]; //or whatever you want to change
为您节省了大量的工作。
也许这个更新的代码有助于某人
[UITabBarItem.appearance setTitleTextAttributes:@{ NSForegroundColorAttributeName : [UIColor lightGrayColor] } forState:UIControlStateNormal]; [UITabBarItem.appearance setTitleTextAttributes:@{ NSForegroundColorAttributeName : [UIColor whiteColor] } forState:UIControlStateSelected];