2012-04-11 136 views
0

我有很多在網絡和堆棧溢出搜索,我看到有很多關於這個問題的問題,所以我想搜索一個解決方案,但我找不到它,我已將UINavigationBar子類化爲將我的自定義圖像用於NavigationBar,但被拉伸以填充導航欄的大小,我如何增加高度?設置UINavigationBar高度

這是多麼我已經做的,我有克里特島只有一個UINavigationController一個XIB文件,然後在界面生成器中我已下定了導航欄CustomClass:

UINib *nib = [UINib nibWithNibName:@"CustomNavigationController" bundle:nil]; 
UINavigationController *navController = 
[[nib instantiateWithOwner:nil options:nil] objectAtIndex:0]; 

那麼我的自定義類:

@implementation CustomNavigationBar

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

我曾試圖改變這裏的高度,self.frame.size.height,但高度尺寸沒有改變,昌只有我縮放的圖像...有一種方法可以用我的圖像大小來設置導航欄的大小?

回答

0

也許你可以試試:

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

不行不行... – Piero 2012-04-11 21:37:12

-1

導航欄的高度是固定的。你不能改變它。儘管可以通過實現自定義視圖來滾動自己的導航欄。