0

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

4

3 に答える 3

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;
于 2011-02-07T09:26:04.093 に答える
2

theNavigationController.navigationBar.barStyle を UIBarStyleBlackTranslucent に設定します

theNavigationController.navigationBar.barStyle = UIBarStyleBlackTranslucent;

ボタンはデフォルトで青色になります。

于 2011-02-07T09:28:10.783 に答える
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 カテゴリを作成しました。

于 2011-04-12T04:12:29.387 に答える