如果我使用UIBarButtonSystemItemCancel,它的颜色将设置为导航栏的颜色。但是,在照片应用程序中,“取消”按钮显示为蓝色背景。我怎样才能将UIBarButtonSystemItemCancel设置为蓝色背景?
答案 0 :(得分: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 :(得分:2)
将theNavigationController.navigationBar.barStyle设置为UIBarStyleBlackTranslucent
theNavigationController.navigationBar.barStyle = UIBarStyleBlackTranslucent;
,默认情况下按钮为蓝色。
答案 2 :(得分: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即可。