我使用“防御性”代码将定制图像设置为UINavigationBar栏 - 它适用于使用ios5或更高版本的设备。iOS上的UINavigationBar上的自定义图像<5.0
一些答案后,我编辑的代码与合并的答案(见下文)
这是正确的&优雅的方式来做到这一点?
if ([[UINavigationBar class] respondsToSelector:@selector(appearance)]) {
UIImage *backgroundImage = [UIImage imageNamed:@"tableTitleView.png"];
[self.navigationController.navigationBar setBackgroundImage:backgroundImage forBarMetrics:UIBarMetricsDefault];
}
else
{
NSString *barBgPath = [[NSBundle mainBundle] pathForResource:@"tableTitleView" ofType:@"png"];
[self.navigationController.navigationBar.layer setContents:(id)[UIImage imageWithContentsOfFile: barBgPath].CGImage];
}
见[此](http://stackoverflow.com/questions/10499259/navigation-controller-not-working-properly/10582222#10582222)链路。我认为这对你会有所帮助。 –