2012-01-31 23 views

回答

1

這可能是更通用的辦法。

創建UINavigationBar的,並在 「.H」 文件

@interface UINavigationBar (UINavigationBarCategory) 

-(void)setBackgroundImage:(UIImage*)image; 

@end 

,並在 「.M」 文件

@implementation UINavigationBar (UINavigationBarCategory) 

-(void)setBackgroundImage: (UIImage*)image 
{ 

    if (image) 
    { 

     UIImageView *img = [[UIImageView alloc]initWithImage: image]; 
     aTabBarBackground.frame = CGRectMake(60,0, 200, 45);//Frame depends upon you 
     [self addSubview:img]; 
     [img release]; 
    } 

} 
@end 

然後從每一個控制器的 'viewWillAppear中' 類別,你可以做像這樣:

[self.navigationController.navigationBar setBackgroundImage: @"abc.png"]; 
+0

好的非常感謝。 – user1057709 2012-01-31 11:30:31

+0

非常感謝您的幫助 – user1057709 2012-01-31 11:32:05

+0

感謝您的幫助.. – user1057709 2012-03-12 06:00:35

0

試試這個代碼...

UINavigationBar *navigationBar=[[self navigationController]navigationBar]; 
UIImage *backgroundImg =[UIImage imageNamed:@"example.png"]; 
[navigationBar setBackgroundImage:backgroundImg forBarMetrics:UIBarMetricsDefault]; 

viewWillAppear中添加以下代碼,並給圖像名稱所顯示的,而不是example.png

+0

感謝您的幫助! – user1057709 2012-01-31 11:31:04

+0

@ user1057709歡迎傢伙... – Deepak 2012-01-31 11:56:27

+0

感謝dude ..現在工作! – user1057709 2012-03-12 05:59:29

相關問題