0

背景圖片我想改變導航Bar.in我的背景圖片我下面更改UINavigationBar的

UINavigationBar *navBar = self.navigationController.navigationBar; 

UIImageView *image1=[[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 320, 50)]; 

image1.image = [UIImage imageNamed:@"image2_ram.jpg"]; 
[navBar setBackgroundImage:image1.image forBarMetrics:UIBarMetricsDefault]; 

圖像代碼更改,但是圖像的高度沒有變化,爲什麼?

+0

你是什麼意思的圖像的高度? –

回答

2

你不應該設置這樣的,如果你正在考慮的iOS 4.0還

使用本

@implementation UINavigationBar (CustomImage) 
- (void)drawRect:(CGRect)rect { 
    UIImage *image = [UIImage imageNamed:@"bgTopBar.png"]; 
    [image drawInRect:CGRectMake(0, 0, self.frame.size.width, self.frame.size.height)]; 
} 
@end 

或爲iOS 5

利用這一點,沒有必要給架到它,你不能改變高度超過44,導航欄的默認高度是

UINavigationBar *navBar = self.navigationController.navigationBar; 
    UIImage *image = [UIImage imageNamed:@"bgTopBar.png"]; 
    [navBar setBackgroundImage:image forBarMetrics:UIBarMetricsDefault];