在iOS中着色UINavigationBar

时间:2009-12-02 14:03:21

标签: ios iphone uinavigationbar

我使用以下颜色为我的导航栏着色:

navigationController.navigationBar.tintColor = [UIColor colorWithRed:0.88 green:0.52 blue:0.27 alpha:1];

一切正常,每个按钮都像条形图一样橙色,但当ic进入自定义右项目菜单时,它显示为蓝色。 这是截图:http://img146.imageshack.us/img146/5605/schermata20091202a14565.png

这是右键的代码:

UIView *container = [[UIView alloc] init];
UIToolbar *tools = [[UIToolbar alloc] initWithFrame:CGRectMake(0, 0, 80, 45)];

NSMutableArray *buttons = [[NSMutableArray alloc] initWithCapacity:2];

UIBarButtonItem *bi = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:@selector(addGadget:)];
bi.style = UIBarButtonItemStyleBordered;
[buttons addObject:bi];
[bi release];

bi = [[UIBarButtonItem alloc]
initWithImage:[UIImage imageNamed:@"less.png"] style:UIBarButtonItemStyleBordered target:self action:@selector(setEditing:)];
[buttons addObject:bi];
[bi release];

[tools setItems:buttons animated:NO];
[buttons release];

self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:tools];
[tools release];

如何让一切变成橙色?

1 个答案:

答案 0 :(得分:1)

您应该将tintColor对象的UIToolbar设置为与UINavigationBar的对象相同。

请注意,UIToolbarUINavigationBar不同,背景渐变/颜色略有不同。尝试将UIToolbar的backgroundColor设置为+[UIColor clearColor]

此外,您可能甚至不需要容器UIView,因为UIToolbarUIView的子类,因此您可以将其单独用作customView。