独立UINavigationBar? [英] Standalone UINavigationBar?

查看:131
本文介绍了独立UINavigationBar?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想要创建一个带有几个按钮在iPhone界面的状态栏下面的几个按钮,控制器是一个简单的UIViewController,因此这是一个用于按钮不用于导航的酒吧。我有工作,但感觉有点笨重,我想知道我是否正确,没有缺少任何快捷方式。





  • 我可能会删除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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆