Изменить цвет UIBarButtonSystemItemCancel - PullRequest
0 голосов
/ 07 февраля 2011

Если я использую UIBarButtonSystemItemCancel, его цвет будет соответствовать цвету панели навигации. Однако в приложении «Фото» кнопка «Отмена» отображается на синем фоне. Как я могу также установить UIBarButtonSystemItemCancel, чтобы иметь синий фон, пожалуйста?

Ответы [ 3 ]

3 голосов
/ 07 февраля 2011

Вы можете использовать изображение как изображение кнопки как

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;
2 голосов
/ 07 февраля 2011

установить для параметра NavigationController.navigationBar.barStyle значение UIBarStyleBlackTranslucent

theNavigationController.navigationBar.barStyle = UIBarStyleBlackTranslucent;

и кнопки будут синие по умолчанию.

1 голос
/ 12 апреля 2011

Есть лучший способ, чем использовать изображение. 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 , которая будет делать это.

...