开发者

Standalone UINavigationBar?

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开发者_StackOverflow社区 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.


Yeah the question repeats but why you don't preferred I.B.? As you don't need navigational functionality then you need to look into an alternate i.e. UIToolBar comes to mind. its usage is same as navigation bar as you need to setItems with NSArray as you are doing.

I hope you will succeed in finding your proper solution.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜