我需要为我的UINavigationBar按钮设置自定义颜色。我正在做以下事情(RGB func是一个定义):
- (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到一个按下的按钮。
发布于 2011-09-06 12:39:10
这里有一种方法:
[[theNavigationBar.subviews objectAtIndex:1] setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
[[theNavigationBar.subviews objectAtIndex:2] setTitleColor:[UIColor redColor] forState:UIControlStateNormal];然而,巨大的警告。这很可能会在将来的操作系统版本中中断,因此不建议这样做。
至少,您应该执行大量测试,并确保您对导航栏的子视图布局的假设是正确的。也可以通过更改UINavigationBar的tintColor属性来更改颜色
myBar.tintColor = [UIColor greenColor];或者您可以访问下面的链接http://www.skylarcantu.com/blog/2009/11/05/changing-colors-of-uinavigationbarbuttons/
发布于 2011-09-06 13:11:59
Change UINavigationItem colour和to set same color to UISegmentControl将帮助您到达目的地。
是将颜色设置为UISegmentControl的示例代码。
发布于 2011-12-01 10:29:59
对于IOS5,必须使用"setBackgroundImage:forBarMetrics:"
尝试此代码以应用所有UINavigationItem / UINavigationBar
if([[UINavigationBar class] respondsToSelector:@selector(appearance)]){ //iOS >=5.0
//use for UINavigationBar Custom image.
[[UINavigationBar appearance] setBackgroundImage:[UIImage imageWithNamed:@"navImage.png"] forBarMetrics:UIBarMetricsDefault];
//use for UINavigationItem custom color
[[UINavigationBar appearance] setTintColor:[UIColor greenColor]];
}https://stackoverflow.com/questions/7314703
复制相似问题