2016-08-01 19 views
0

這裏的工作是什麼,我在我的AppDelegatesetTitleTextAttributes不NSForegroundColorAttributeName

self.tabBarController.delegate = self; 
NSDictionary *unSelectedAttributes = [NSDictionary dictionaryWithObjectsAndKeys: 
            [Utility primaryColor], NSForegroundColorAttributeName, nil]; 
NSDictionary *selectedAttributes = [NSDictionary dictionaryWithObjectsAndKeys: 
             [UIColor whiteColor], NSForegroundColorAttributeName, nil]; 


[[UITabBarItem appearance] setTitleTextAttributes:unSelectedAttributes 
             forState:UIControlStateNormal]; 
[[UITabBarItem appearance] setTitleTextAttributes:selectedAttributes 
             forState:UIControlStateSelected]; 

做什麼,這是我的firstViewController:

[[UINavigationBar appearance] setBarTintColor:[Utility primaryColor]]; 
[[UITabBar appearance] setTintColor:[UIColor whiteColor]]; 
UITabBar * tabBar = self.tabBarController.tabBar; 
UIImage *tabImage = [UIHelper makeImageWithSizeAndColor:[Utility primaryColor] : CGSizeMake(tabBar.frame.size.width/2, tabBar.frame.size.height)]; 
tabImage = [tabImage imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]; 
tabBar.selectionIndicatorImage = [UIHelper makeImageWithSizeAndColor:[Utility primaryColor] : CGSizeMake(tabBar.frame.size.width/tabBar.items.count, tabBar.frame.size.height)]; 

我的標籤正在改變顏色,但文本保持白色和灰色。它不會根據setTitleTextAttributes改變顏色。

回答

0

嘗試使用此代碼更改文字顏色。

[[UITabBarItem appearance] setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys: 
                  [UIColor whiteColor], UITextAttributeTextColor, 
                  nil] forState:UIControlStateNormal]; 
     UIColor *titleHighlightedColor = [UIColor colorWithRed:153/255.0 green:192/255.0 blue:48/255.0 alpha:1.0]; 
     [[UITabBarItem appearance] setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys: 
                  titleHighlightedColor, UITextAttributeTextColor, 
                  nil] forState:UIControlStateHighlighted]; 

好吧其棄用。你可以試試這個代碼

[[UITabBarItem appearance] setTitleTextAttributes:@{ NSForegroundColorAttributeName : [UIColor blackColor] } 
              forState:UIControlStateNormal]; 
    [[UITabBarItem appearance] setTitleTextAttributes:@{ NSForegroundColorAttributeName : [UIColor redColor] } 
              forState:UIControlStateSelected]; 

我想你的代碼還,那也是工作的罰款。

NSDictionary *unSelectedAttributes = [NSDictionary dictionaryWithObjectsAndKeys: 
              [UIColor blackColor], NSForegroundColorAttributeName, nil]; 

    NSDictionary *selectedAttributes = [NSDictionary dictionaryWithObjectsAndKeys: 
             [UIColor redColor], NSForegroundColorAttributeName, nil]; 


    [[UITabBarItem appearance] setTitleTextAttributes:unSelectedAttributes 
              forState:UIControlStateNormal]; 
    [[UITabBarItem appearance] setTitleTextAttributes:selectedAttributes 
              forState:UIControlStateSelected]; 
+0

我認爲'UITextAttributeTextColor'已被棄用。但是,我確定我會試一試。 – user1324887

+0

與我正在做的一樣。無論如何試過它,不起作用 – user1324887

+0

它的工作。我剛剛檢查過。 – Nilesh

相關問題