2013-06-05 51 views
0

此代码如何在我的UIView上不生成UINavigationBar?以编程方式创建UINavigationBar

//create the view 
UIView *view = [[UIView alloc] init]; 
view.backgroundColor = [UIColor whiteColor]; 

//everything for tabbar 
UINavigationBar *navBar = [[UINavigationBar alloc] init]; 

//add the components to the view 
[view addSubview: navBar]; 

//show the view 
self.view = view; 

我看到白色的视图,但没有NavBar。任何帮助?我究竟做错了什么?

+1

'view.frame = CGRectMake(x,y,w,h); navBar.frame = view.bounds;' – 2013-06-05 19:36:22

回答

1

设置导航栏的框架,并将其添加为视图的子视图,以供它看到。为任何视图设置框架,使其位于其超级视图的坐标系中。

[navBar setFrame:CGRectMake(0,0,CGRectGetWidth(view.frame),44)]; 
[self.view addSubview:navBar]; 

另外它的导航栏,我不知道你愿意从你发布的代码中看到什么标签栏。

+0

糟糕。我将NavBars和TabBars混合起来。 –

+0

'[self.view addSubview:navBar];'在我的情况下不起作用。我需要将它添加到'UIView * view'中,所以我需要使用'[view addSubview:navBar];' –

+0

即使使用您的代码,navBar也不会出现在所有... –