我希望在statusBar下面的iPhone界面顶部创建一个带有几个按钮的栏,控制器是一个简单的UIViewController,因此这是一个不用于导航按钮的栏。我有事情可行,但感觉有点笨重,我想知道我是否做得对,并没有错过任何捷径。
代码:
- (void)loadView {
// VIEW
UIView *tempView = [[UIView alloc] initWithFrame:screenFrame];
// NAV BAR
UINavigationBar *tempNavigationBar = [[UINavigationBar alloc] initWithFrame:CGRectMake(0, 0, 320, 44)];
[tempNavigationBar setBarStyle:UIBarStyleBlack];
UIBarButtonItem *testButton = [[UIBarButtonItem alloc] initWithTitle:@"TEST" style:UIBarButtonItemStyleBordered target:self action:nil];
UINavigationItem *navItem = [[UINavigationItem alloc] init];
[navItem setLeftBarButtonItem:testButton];
[testButton release];
[tempNavigationBar setItems:[NSArray arrayWithObject:navItem]];
[tempView addSubview:tempNavigationBar];
[tempNavigationBar release];
[navItem release];
[self setView:tempView];
[tempView release];
}
答案 0 :(得分:1)
这对我来说没问题。另一种方法是在Interface Builder中执行此操作,但这是完全不同的事情。
如果您打算支持自动旋转,则可能需要添加更多代码来为导航栏设置自动调整大小的掩码,以便正确扩展。实际上,我会使用Interface Builder来实现这一点,因为我很想看我的自动调整大小的掩码。
答案 1 :(得分:1)
是的,问题重复,但为什么你不喜欢I.B.?由于您不需要导航功能,因此您需要查看备用,即UIToolBar。它的用法与导航栏相同,因为您需要使用NSArray setItems 。
我希望你能成功找到合适的解决方案。