2011-02-07 16 views
0

UIBarButtonSystemItemCancelを使用すると、色はナビゲーションバーの色に設定されます。ただし、写真アプリでは、「キャンセル」ボタンが青い背景で表示されます。青い背景を持つようにUIBarButtonSystemItemCancelを設定するにはどうしたらいいですか?UIBarButtonSystemItemCancelの色を変更します。

答えて

3

UIImage *buttonImage = [UIImage imageNamed:@"image.png"]; 

//create the button and assign the image 
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom]; 
[button setImage:buttonImage forState:UIControlStateNormal]; 


//create a UIBarButtonItem with the button as a custom view 
//UIBarButtonItem *customBarItem = [[UIBarButtonItem alloc] initWithCustomView:button]; 

[button addTarget:self action:@selector(clickActionItem:) forControlEvents:UIControlEventTouchUpInside]; 

UIBarButtonItem *rightBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:button ]; 




self.navigationItem.rightBarButtonItem = rightBarButtonItem; 
+1

左にバーボタンアイテムを配置する場合は、self.navigationItem.leftBarButtonItem = urbarbutton変数から設定できます。 –

+0

ありがとうございます、あなたの提案は良い回避策ですが、回避策なしでこれが可能であることを期待していました – CastToInteger

2

がUIBarStyleBlackTranslucent

theNavigationController.navigationBar.barStyle = UIBarStyleBlackTranslucent; 

とボタンにtheNavigationController.navigationBar.barStyleを設定すると、あなたがボタン画像として画像を使用することができますが、デフォルトでは青になります。

+0

残念ながら、私はnavbar用のカスタムティントカラーを持っています。私はこれを試したが、うまくいかない – CastToInteger

1

画像を使用するよりも良い方法があります。 UISegmentedControlは、UIBarButtonItemと同様に見えるように設定でき、UISegmentedControlにはtintColorプロパティがあります。

UISegmentedControl *button = [[[UISegmentedControl alloc] initWithItems:[NSArray arrayWithObjects:itemTitle, nil]] autorelease]; 
    button.momentary = YES; 
    button.segmentedControlStyle = UISegmentedControlStyleBar; 
    button.tintColor = color; 
    [button addTarget:theTarget action:selector forControlEvents:UIControlEventValueChanged]; 

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

私はこれを行うUIBarButtonItem categoryを構築しました。

関連する問題