如果我使用 UIBarButtonSystemItemCancel,它的颜色设置为导航栏的颜色。但是,在照片应用程序中,“取消”按钮以蓝色背景显示。请问如何将 UIBarButtonSystemItemCancel 设置为蓝色背景?
问问题
1371 次
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 回答