![](/img/trans.png)
[英]How to change the text color of a UITabbarItem and how to add a custom TabBar in an iPhone Application?
[英]change tabbar text color,iPhone
我以編程方式創建了一個tabbar。
我們可以更改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]
替換self.tabBarItem
以更改所有tabbar項。 如果你想改變它們,我建議你把代碼放在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];
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.