5

アプリに明るい色の背景を持つ UIBarButtonItems があり、標準の白ではなく、より暗い色でアイコンを着色したいと考えていました。

このような:

ここに画像の説明を入力

を使用してテキストに色を付けることができました

[[UIBarButtonItem appearance] setTitleTextAttributes:@{UITextAttributeTextColor: [UIColor blackColor]} forState:UIControlStateNormal];,

しかし、アイコンの色を変更する方法がわかりません。

それは可能ですか?

4

3 に答える 3

3

UIButtonカスタム イメージを使用して を作成し、UIBarButtonItemカスタムUIButtonビューとして を 使用して を作成します。

UIImage *buttonImage = [UIImage imageNamed:@"image"]; // Tint this image programmatically
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
[button setImage:buttonImage forState:UIControlStateNormal];
button.frame = CGRectMake(0.0, 0.0, buttonImage.size.width, buttonImage.size.height);
[button addTarget:self action:@selector(action:) forControlEvents:UIControlEventTouchUpInside];

UIBarButtonItem *barButtonItem = [[[UIBarButtonItem alloc] initWithCustomView:button] autorelease];

これは主に iOS 6 以下用であることに注意してください。iOS 7 以降では、この動作を無料で取得できますtintColor

于 2014-07-16T19:24:13.910 に答える
1

これはナビゲーションバーで機能すると思います:

[[UINavigationBar appearance] setTintColor:[UIColor blackColor]];

[[UIBarButtonItem appearance] setTintColor:[UIColor blackColor]];

もちろん、ストーリーボード オプションで全体の色合いを変更することもできます (私の Mac では変更できないため、正確な場所はわかりません)。

于 2013-10-17T14:45:48.537 に答える
0
[myBarButton_name setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys: [UIColor yellowColor], UITextAttributeTextColor,nil] forState:UIControlStateNormal];
于 2013-10-17T13:33:16.083 に答える