2012-04-11 11 views
2

私のアプリにはいくつかのViewControllerがあり、その中にはナビゲーションスタックにプッシュされたときに別のナビゲーションバーの背景画像を使用したいと思うものがあります。例えばiOS 5のUINavigationBarに異なる背景画像を設定する

、私mainViewController負荷がアップし、私はこれを持っている場合:

同様に
- (void)viewWillAppear:(BOOL)animated 
{ 
    [super viewWillAppear:animated]; 
    NSLog(@"Setting toolbar for iOS 5+"); 
    UIImage * navbarImage = [UIImage imageNamed:@"navbar01.png"]; 
    [[UINavigationBar appearance] setBackgroundImage:navbarImage forBarMetrics:UIBarMetricsDefault]; 
} 

、私の他のViewControllerは、ナビゲーションスタックにプッシュされたとき、私は別のを使用する以外は、上記と同じコードを使用していますUIImage(navbar02.png)。

ただし、ナビゲーションバーは設定した最初の画像から変更されません。新しいビューが表示されたら、UINavigationBarの背景イメージを変更する方法はありますか?

ありがとうございました!ここで

答えて

1
float version = [[[UIDevice currentDevice] systemVersion] floatValue]; 
// NSLog(@"%f",version); 
if (version >= 5.0) { 
    UIImage *backgroundImage = [UIImage imageNamed:@"image.png"]; 
    [self.navigationController.navigationBar setBackgroundImage:backgroundImage forBarMetrics:UIBarMetricsDefault]; 
} 
else 
{ 
    // UIImage *backgroundImage = [UIImage imageNamed:@"image.png"]; 
    NSString *barBgPath = [[NSBundle mainBundle] pathForResource:@"NavBar" ofType:@"png"]; 
    [self.navigationController.navigationBar.layer setContents:(id)[UIImage imageWithContentsOfFile: barBgPath].CGImage]; 
} 

その私のために首尾よく働いて...多分それはあなたを助けるでしょう。

+0

それは私にとっても素晴らしい仕事の仕事の仕事です。それを維持する –

+0

@Pravi njoy buddy ... ty :) –

関連する問題