独立UINavigationBar的?(Standalone UINavigationBar?)

2019-09-29 05:07发布

我在看不到状态栏iPhone界面的顶部创建了几个按钮的一间酒吧,控制器是一个简单的UIViewController所以这是不是导航按钮了吧。 我已经得到的东西的工作,但感觉有点麻烦,我想知道如果我这样做是正确且没有遗漏任何快捷方式。

  • 没有动作/选择:设置但是作为我只是设置此功能。
  • 我可能会删除NSArray的简便方法,并添加分配/释放。

码:

- (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];
}

Answer 1:

这看起来好了给我。 另一种方法是这样做在Interface Builder,但是这是一个完全不同的事情。

如果您打算支持自动旋转,您可能需要添加一些代码来设置自动调整大小面具为您导航栏,以便它正确扩展。 事实上,我会使用Interface Builder对于这一点,因为我对我的可视化口罩自动调整大小大。



Answer 2:

是啊这个问题重复,但你为什么不首选IB? 当你不需要导航功能,那么你需要寻找到一个替代即UIToolBar想到的。 如您需要的NSArray到setItems因为你正在做它的用法是一样的导航栏。

我希望你能找到你的妥善解决取得成功。



文章来源: Standalone UINavigationBar?