私のナビゲーション バーには、カスタム アイコンを持つ rightBarButtonItems がいくつかあります (アイコン イメージは白で、iOS 6 の基本的な配色でうまく機能します)。
iOS 7 では、initWithTitle (コード スニペット 1 を参照) を使用して画像を読み込むと、アイコンの「白」の色が適切なグローバル ティント (この場合は濃い青の特定の色) に置き換えられます。
コード スニペット 1 :
UIBarButtonItem *refreshButton = [[UIBarButtonItem alloc] initWithTitle:@"" style:(UIBarButtonItemStyle) UIBarButtonSystemItemCancel target:(self) action:@selector(refreshList)];
refreshButton.image = [UIImage imageNamed:@"RefreshIcon.png"];
ただし、initWithCustomView を使用して、アイコンがビューの外に移動する原因となっていた動作の奇妙な変化を克服する必要がありました。基本的なアイデアは、アイコンのサイズを具体的に設定することでした。initWithCustomView はサイズ変更の問題を解決しましたが、ボタン イメージをグローバルな色合いで表示せず、イメージの色 (白) で表示します。コード スニペット 2 は、initWithCustomView を使用してボタンを作成する方法を示しています。
コード スニペット 2 :
CGRect frameCustomButton2 = CGRectMake(0.0, 0.0, 18.0, 18.0);
UIButton *customButton2 = [[UIButton alloc] initWithFrame:frameCustomButton2];
[customButton2 setBackgroundImage:iconRefreshButton forState:UIControlStateNormal];
UIBarButtonItem *barCustomButton2 =[[UIBarButtonItem alloc] initWithCustomView:customButton2 ];
barCustomButton2.image = iconRefreshButton;
[customButton2 addTarget:self action:@selector(refreshList) forControlEvents:UIControlEventTouchUpInside];
もちろん、このコードはすべて (void)viewDidLoad にあります。私は次のようなことを試しました:
barCustomButton2.tintColor = [UIColor blackColor]; //doesn't work
または [barButtonAppearance setTintColor:[UIColor blackColor]]; // 機能しません
また、画像の白色を上書きしません。ビューがグローバルティントカラーを見た後にカスタムビューの作成が行われるようなものですか?
ボタン アイコンがグローバルな色合いになるようにするにはどうすればよいですか?
ありがとう!