我想更改导航栏的背景图像(或颜色),但是由于某些原因,它不起作用。
我四处搜索,发现在iOS 5.0+(我正在运行6.1)上,这应该可以工作:
[self.navigationController.navigationBar setBackgroundImage:navigationBackgroundImage forBarMetrics:UIBarMetricsDefault];
[self.navigationController.navigationBar setBackgroundColor:[UIColor redColor]];
现在这些都不起作用。还尝试了:
self.navigationController.navigationBar.backgroundColor = [UIColor redColor];
现在,我正在考虑将其分配给错误的对象,但这可行:
UIImageView *titleImage = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"scr1_title"]];
self.navigationItem.titleView = titleImage;
在视图控制器中使用此代码来更改导航栏背景图像。
if([[UINavigationBar class] respondsToSelector:@selector(appearance)]) //iOS >=5.0
{
UIImage * navBarImage = [UIImage imageNamed:@"image.png"] ;
[[UINavigationBar appearance]setBackgroundImage: navBarImage forBarMetrics:UIBarMetricsDefault];
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句