在 iOS 中为 UINavigationBar 着色

发布于 2024-08-13 01:23:46 字数 1261 浏览 5 评论 0原文

我将导航栏着色为橙色:

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

半寸时光 2024-08-20 01:23:46

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

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

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

You should set the tintColor of the UIToolbar object to be the same as that of the UINavigationBar.

Note that a UIToolbar is not the same as a UINavigationBar, 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, since UIToolbar is a subclass of UIView, so you can use it as customView just by itself.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文