我使用「防禦性」代碼將定製圖像設置爲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)鏈路。我認爲這對你會有所幫助。 –