更改 UINavigationItem 颜色
我需要为 UINavigationBar 按钮设置自定义颜色。 我正在做以下事情(RGB 函数是一个定义):
- (void)viewWillAppear:(BOOL)animated
{
for (UIView *view in self.navigationController.navigationBar.subviews)
if ([[[view class] description] isEqualToString:@"UINavigationButton"])
[(UINavigationButton *)view setTintColor:RGB(22.0,38.0,111.0)];
}
应用程序加载时一切看起来都很好。离开视图并返回后,颜色恢复为默认值。
其次,我需要为按下的按钮设置与 UISegmentedControl 相同的颜色。
I need to set custom colors to my UINavigationBar buttons.
I'm doing the following thing(RGB func is a define):
- (void)viewWillAppear:(BOOL)animated
{
for (UIView *view in self.navigationController.navigationBar.subviews)
if ([[[view class] description] isEqualToString:@"UINavigationButton"])
[(UINavigationButton *)view setTintColor:RGB(22.0,38.0,111.0)];
}
Everything looks fine on app load. after leaving the view and getting back the color returns to default.
Secondly I need to set the same colour to UISegmentedControl to a pressed button.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
[更改 UINavigationItem 颜色](http://www.skylarcantu.com/blog/2009/11/05/changing-colors-of-uinavigationbarbuttons/"更改 UINavigationBarButtons 的颜色") 和 为 UISegmentControl 设置相同的颜色将帮助您到达目的地。
这里是为 UISegmentControl 设置颜色的示例代码。
[Change UINavigationItem colour](http://www.skylarcantu.com/blog/2009/11/05/changing-colors-of-uinavigationbarbuttons/"Changing colors of UINavigationBarButtons") and to set same color to UISegmentControl will help you to reach to your destination.
Here is a sample code for to set color to UISegmentControl.
这是一种方法:
但是,巨大的,警告。这很可能会在未来的操作系统版本中出现问题,因此不建议这样做。
至少您应该执行大量测试并确保您对导航栏子视图布局的假设是正确的。
或者
您可以通过更改 UINavigationBar 的tintColor 属性
或
您可以点击以下链接
http://www.skylarcantu.com/blog/ 2009/11/05/改变uinavigationbarbuttons的颜色/
Here's one way:
However, HUGE, caveat. This is highly likely to break on a future OS release and is not recommended.
At the very least you should perform a lot of testing and make sure you your assumptions of the subview layout of the navigation bar are correct.
or
You can change the color by changing the tintColor property of the UINavigationBar
or
You can follow the below link
http://www.skylarcantu.com/blog/2009/11/05/changing-colors-of-uinavigationbarbuttons/
对于IOS5,必须使用 "setBackgroundImage:forBarMetrics :"
尝试此代码来应用所有 UINavigationItem / UINavigationBar
For IOS5 will have to use "setBackgroundImage:forBarMetrics:"
try this code to apply all UINavigationItem / UINavigationBar