[英]Changing navigation bar image - not working
我想更改导航栏的背景图像(或颜色),但是由于某些原因,它不起作用。
我四处搜索,发现在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];
}
您可以在导航控制器的导航栏上设置色调颜色。 确保选择正确的开启,如下面的屏幕截图所示。
设置图像。
[[UINavigationBar appearance] setBackgroundImage:[UIImage imageNamed:@"navigationBar"] forBarMetrics:UIBarMetricsDefault];
内
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.