2011-05-10 43 views
4

我無法在導航欄(或導航控制器,位於應用程序頂部)中設置完整圖像。剩下的空間很小。當我把信息按鈕放在圖片上時,我怎樣才能解決這個問題無法在導航欄中設置完整圖像

這裏是我的代碼,請看看

UIImageView* img = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"headerBG.png"]]; 
    img.frame = CGRectMake(0, 0, 320, 44); 
    self.navigationItem.titleView =img; 
    [img release]; 


UIButton * infoDarkButtonType = [[UIButton buttonWithType:UIButtonTypeInfoLight] retain]; 
    infoDarkButtonType.frame = CGRectMake(0.0, 0.0, 25.0, 25.0); 
    infoDarkButtonType.backgroundColor = [UIColor clearColor]; 
    [infoDarkButtonType addTarget:self action:@selector(showInfo) forControlEvents:UIControlEventTouchUpInside]; 
    UIBarButtonItem *infoButton = [[UIBarButtonItem alloc] initWithCustomView:infoDarkButtonType]; 
    self.navigationItem.leftBarButtonItem = infoButton; 
    [infoDarkButtonType release]; 
    [infoButton release]; 

非常感謝你。

我。

回答

2

如果你想在導航欄上顯示的圖像,你不能嘗試這個

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

YEP它可以工作,但它會改變每個頁面的所有導航欄。我只是想改變1頁。請你能指導我更多。 – crazyoxygen 2011-05-10 07:25:11

+0

您是否可以隱藏導航欄並改爲使用與導航欄類似的自定義視圖,並使用必要的按鈕。 – visakh7 2011-05-10 08:11:55

+0

對不起。恐怕不行。原因它來自導航控制器 – crazyoxygen 2011-05-10 08:22:26

0

使用此代碼行局在NavigationController添加圖片...

UIImageView* img = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"headerBG.png"]]; 
img.frame = CGRectMake(0, 0, 320, 44); 
[self.navigationController.navigationItem addSubView:img]; 
[img release]; 

現在,你在設定圖像導航..