在 iOS 中为 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];
How to make everything to be Orange?
I colorized orange my Navigation bar with:
navigationController.navigationBar.tintColor = [UIColor colorWithRed:0.88 green:0.52 blue:0.27 alpha:1];
Everything works ok, every button is as orange as the bar, but when ic cames to a custom right item menu, it shows it blue.
This is a screenshot: http://img146.imageshack.us/img146/5605/schermata20091202a14565.png
and this is the code for the right buttons:
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];
How to make everything to be orange?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您应该将
UIToolbar
对象的tintColor
设置为与UINavigationBar
的相同。请注意,
UIToolbar
与UINavigationBar
不同,背景渐变/颜色有点不同。尝试将 UIToolbar 的背景颜色设置为+[UIColor clearColor]
另外,您可能甚至不需要容器
UIView
,因为UIToolbar
是UIView
的子类,因此您可以将其单独用作 customView。You should set the
tintColor
of theUIToolbar
object to be the same as that of theUINavigationBar
.Note that a
UIToolbar
is not the same as aUINavigationBar
, the background gradient/color is a bit different. Try setting the backgroundColor of the UIToolbar to+[UIColor clearColor]
Also, you probably don't even need the container
UIView
, sinceUIToolbar
is a subclass ofUIView
, so you can use it as customView just by itself.