2010-08-06 90 views
5

我已經看到了一些應用程序,在導航欄實際上比默認44px小做,有一個UIView(有功能)上述導航欄...你可以在UINavigationBar上面添加一個UIView嗎?

我想不止一個自定義的背景圖片,我設法弄清楚該怎麼做,但我不知道從哪裏開始做這樣的事情。

任何幫助是極大的讚賞:) 馬克

回答

3

我發現了一個排序的方式來做到這一點:

UINavigationBar *navBar = [[UINavigationBar alloc] initWithFrame: CGRectMake(0.0f, 20.0f, 320.0f, 32.0f)]; 

UIView *tempView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 20)]; 
UIImageView *back = [[UIImageView alloc] initWithImage: [UIImage imageNamed:@"logo.png"]]; 
[back setFrame: CGRectMake(0, 0, 320, 20)]; 
[tempView addSubview: back]; 
[[self view] addSubview: tempView]; 

[[self view] addSubview: navBar]; 

UINavigationItem *navItem = [[UINavigationItem alloc] initWithTitle: @"Controls"]; 
[navBar pushNavigationItem:navItem animated:NO]; 

這似乎這樣的伎倆,但我似乎無法弄清楚如何將此'導入'導航控制器,以便返回按鈕正常工作,此刻我必須手動在導航項中插入leftBarButtonItem,後退按鈕似乎永遠不會顯示...

0

是的,你可以,

UINavigationBar *navBar = [[UINavigationBar alloc] initWithFrame: CGRectMake(0.0f, 20.0f, 320.0f, 32.0f)]; 
UIView *tempView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 20)]; 
navBar.navigationBar.layer.zPosition =-1; 
self.view insertSubview:navBar atIndex:[[self.view subviews] count]]; 
[self.view insertSubview:tempView atIndex:[[self.view subviews] count]]; 
相關問題