2010-08-06 81 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]]; 
相关问题