19

注: SOにはいくつかの同様の質問がありますが、カスタムとシステムの両方のUITabBarItemsの選択されていない外観を変更したいという私の特定の問題には、どれも当てはまらないようです。)

私はiOS7で働いています。いくつかのボタンを持つ UITabBar があります。それらのいくつかは私のボタンであり、いくつかはシステムボタンです。例:

UITabBarItem *searchButton = [[UITabBarItem alloc] initWithTabBarSystemItem: UITabBarSystemItemSearch    tag: navSearchItem];
UITabBarItem *bookMkButton = [[UITabBarItem alloc] initWithTabBarSystemItem: UITabBarSystemItemBookmarks tag: navBookmarksItem];
UITabBarItem *homeButton   = [[UITabBarItem alloc] initWithTitle: @"Home"     image: [self tabBarImageNamed: @"home-tab"]     tag: navHomeItem];
UITabBarItem *setingButton = [[UITabBarItem alloc] initWithTitle: @"Settings" image: [self tabBarImageNamed: @"settings-tab"] tag: navSettingsItem];

navTabBar.items = @[ searchButton, homeButton, bookMkButton, setingButton];

選択したボタンの色合いは、次のように簡単に設定できます。

[[UITabBar appearance] setSelectedImageTintColor: MY_FAVORITE_COLOR];

選択されていないボタンのテキストの色を白に設定できます。

[[UITabBarItem appearance] setTitleTextAttributes: [NSDictionary dictionaryWithObjectsAndKeys: [UIColor whiteColor], UITextAttributeTextColor, nil]
                                         forState: UIControlStateNormal];

私がやりたいのは、UNSELECTEDボタンの画像の色合いを白に設定することです。選択されていない画像を簡単に設定できましたが、それは私のボタンでしか機能しません。システムボタンにもこれを行いたいです。つまり、検索とブックマークのボタンも選択されていない白にしたいのです。

カスタム ボタンを作成するためにアイコンを再作成しようとすると、Apple が文句を言うことは間違いありません。ドキュメントはかなり具体的で、Apple のアイコンにリモートで似たようなことをするべきではありません。

ヒント?

ありがとう!

編集: unselected=white が必要な理由は、私のデザインした背景に対して、デフォルトの灰色がアイコン/テキストを目に難しくするからです。

4

6 に答える 6

12

カスタムの選択されていない UITabBarItem 画像を白に設定することに成功した唯一の方法は、次の (白い) 画像を使用して特定のレンダリング モードで読み込むことでした。

UIImage *tabImage = [[UIImage imageNamed:@"white_tab_item"] 
                      imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];

self.tabItem.image = tabImage;

クラスの UITabBarItem アウトレットである「tabItem」

クレジットは Aaron Brager の回答に移動します: UITabBarController unselected icon image tint

于 2014-03-06T16:54:17.657 に答える
2

unselectedItemTintColoriOS 10 では、選択されていない項目の色合いを指定するために使用できるUITabBar が公開されています。詳細については、ドキュメントを参照してください。

これは、タブ バーを構成するときに、次の色合いのオプションがあることを意味します。

  • tintColor選択したタブに適用されます
  • unselectedItemTintColor選択されていないすべてのタブに適用されます
于 2016-11-22T12:08:15.343 に答える
0

Storyboard を使用している場合は、ImageforBar ItemSelected Imagefor の両方を設定して、 でSelected Bar Item変更されていない画像を取得することもできますtabBar

于 2016-05-31T10:17:06.487 に答える
0

選択ボタンのタイトルの色を変更するこのコード

////これらのコードを ios7 用に定義します

  #define SYSTEM_VERSION_EQUAL_TO(v)                  ([[[UIDevice currentDevice] systemVersion]   compare:v options:NSNumericSearch] == NSOrderedSame)

 #define SYSTEM_VERSION_GREATER_THAN(v)              ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] == NSOrderedDescending)

 #define SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(v)  ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] != NSOrderedAscending)

 #define SYSTEM_VERSION_LESS_THAN(v)                 ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] == NSOrderedAscending)

 #define SYSTEM_VERSION_LESS_THAN_OR_EQUAL_TO(v)     ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] != NSOrderedDescending)





 if (SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"7.0")){

   NSLog(@"ios77777");


[[UITabBarItem appearance] setTitleTextAttributes:@{NSFontAttributeName : [UIFont            fontWithName:@"HelveticaNeue-Bold" size:10.0f],
                                                        NSForegroundColorAttributeName :   [UIColor redColor]



 }

      forState:UIControlStateNormal];

    }
于 2014-01-03T12:35:39.893 に答える