4

プログラムでタブバーを作成しました。

タブバーアイテムのタイトルの色を変更できますか?デフォルトは白で、黒にしようとしています。

何かのようなもの

 tabbaritem.text.textcolor=[UIcolor Blackcolor];

ありがとう

4

3 に答える 3

31

iOS5では、外観プロキシを使用してタイトルの色を変更します。

特定のタブバーアイテムの場合:

[[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];

または、に置き換えself.tabBarItem[UITabBarItem appearance]、すべてのタブバーアイテムを変更します。それらをすべて変更したい場合は、コードをappdelegateに配置することをお勧めしますdidFinishLaunchingWithOptions:

于 2012-07-05T12:10:38.667 に答える
2

ただ何か他のもの..。

iOS 5で標準の外観を設定するには:

AppDelegate.mで次のことを行います。

[[UITabBar appearance] setTintColor:myColor]; //or whatever you want to change

多くの作業を節約できます。

于 2012-07-05T12:15:44.593 に答える
0

たぶん、この更新されたコードは誰かを助けます:

[UITabBarItem.appearance setTitleTextAttributes:@{
                                                  NSForegroundColorAttributeName : [UIColor lightGrayColor] } forState:UIControlStateNormal];

[UITabBarItem.appearance setTitleTextAttributes:@{
                                                  NSForegroundColorAttributeName : [UIColor whiteColor] }     forState:UIControlStateSelected];
于 2015-11-02T06:20:43.947 に答える