簡體   English   中英

更改標簽欄文字顏色,iPhone

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM