2013-10-17 10 views
5

私は、アプリケーション内に明るい色の背景を持つUIBarButtonItemsを持っています。標準の白ではなく、暗い色のアイコンに色を付けたいと思っていました。このようiOS 6、UIBarButtonItemの白いアイコンを色づける方法は?

enter image description here

私は

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

を使用してテキストを色付けすることができましたが、私は、アイコンの色を変更する方法を見つけ出すことはできません。

これは可能ですか?

+0

[色付きの画像でUIBarButtonItemを作成することはできますか?](http://stackoverflow.com/questions/1835260/can-i-have-a-uibarbuttonitem-with-colored-image) –

+0

+1。このことに気付かなかった。 – Bhavin

答えて

0

次のコードを使用すると役立つ場合があります。

[myBarButton_name setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys: [UIColor yellowColor], UITextAttributeTextColor,nil] forState:UIControlStateNormal]; 
+0

私はまだテストしていませんが、1:テキストカラー(アイコンカラーではありません)だけが変わると私は信じています。 2:私はむしろボタンごとにグローバルな変更を加えることにします。 – Guilherme

+0

UIBarButtonItemの色を変更したいのですか? – iPatel

+0

@Guilherme http://stackoverflow.com/questions/4518617/setting-bar-button-item-color-in-a-custom-navigation-bar and http://stackoverflow.com/questions/13677703/change-uibarbuttonitems -color – iPatel

1

私は、これは、ナビゲーションバーで働くかもしれないと考えている:

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

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

そしてもちろん、あなたも(ない私のMac上でストーリーボードオプションで全体色合いを変え、そうすることができますすることができます」 t)が正確な場所を教えてくれ

3

は、カスタムビューとしてUIButtonUIBarButtonItemを作成し、カスタムイメージを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で無料でこの動作を取得します。

関連する問題