独立UINavigationBar? [英] Standalone UINavigationBar?
问题描述
- 我可能会删除NSArray方便的方法并添加一个alloc / release。
代码:
- (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:@TESTstyle: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];
}
一个替代方法是在Interface Builder中执行此操作,但这是一个完全不同的事情。
如果您打算支持自动旋转,您可能需要添加一些代码自动调整导航栏的掩码,使其正确扩展。实际上,我会使用Interface Builder来实现这一点,因为我很想看到我的自动调整大小的掩码。
I am looking to create a bar with a couple of buttons at the top of the iPhone interface just under the statusBar, the controller is a simple UIViewController so this is a bar for buttons not for navigation. I have got things working but it feels a little clunky and I was wondering if I was doing it right and not missing any shortcuts.
- There is no action / selector: set yet as I am just setting this up.
- I will probably remove the NSArray convenience method and add an alloc/release.
Code:
- (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];
}
That looks alright to me. An alternative would be to do this in Interface Builder, but that's a completely different matter.
If you intend to support autorotation, you may have to add some more code to set autoresize masks for your navigation bar so it expands correctly. Actually, I would use Interface Builder for this, because I'm big on visualizing my autoresize masks.
这篇关于独立UINavigationBar?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!