如何在 iPhone 的自定义导航栏中创建导航栏项目?

发布于 2024-10-13 05:51:47 字数 545 浏览 3 评论 0原文

我创建了一个自定义视图,并添加了一个 Web 视图作为该自定义视图的子视图。我以编程方式创建了一个导航栏。现在我想在该视图中创建一个左或右导航栏按钮。

navigBar = [[UINavigationBar alloc] initWithFrame:CGRectMake(0, 0, 320, 44)];

navigBar.tintColor = [UIColor blackColor];

[self.view addSubview:navigBar];

UIBarButtonItem *homeButton = [[UIBarButtonItem alloc] initWithTitle:@"Home" style:UIBarButtonSystemItemAction target:self action:@selector(homeButtonAction)];

navigBar.rightBarButtonItem = homeButton; // it's not supports

如何在自定义导航栏中创建导航栏项目?我想删除自定义视图。所以请帮助我!

谢谢。

I have created one custom view and added a web view as subview of that custom view. And i have created one navigation bar in programmatically. Now i want to create one Left or Right navigation bar buttons in that view.

navigBar = [[UINavigationBar alloc] initWithFrame:CGRectMake(0, 0, 320, 44)];

navigBar.tintColor = [UIColor blackColor];

[self.view addSubview:navigBar];

UIBarButtonItem *homeButton = [[UIBarButtonItem alloc] initWithTitle:@"Home" style:UIBarButtonSystemItemAction target:self action:@selector(homeButtonAction)];

navigBar.rightBarButtonItem = homeButton; // it's not supports

How can i create navigation bar item in the custom navigation bar?, i want to remove the custom view. So please Help me out!

Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

傾城如夢未必闌珊 2024-10-20 05:51:47

在您的导航栏引用中,您可以调用这两种方法:

- (void)pushNavigationItem:(UINavigationItem *)item animated:(BOOL)animated
- (UINavigationItem *)popNavigationItemAnimated:(BOOL)animated

在您的自定义视图控制器类中编写如下内容:

self.navigationItem.leftBarButtonItem = yourButton;
self.navigationItem.rightBarButtonItem = yourSecondButton;

因此您可以编写如下内容:

[myNavBarReference pushNavigationItem:self.navigationItem animated:NO];

On your navigationbar reference you could invoke the two methods:

- (void)pushNavigationItem:(UINavigationItem *)item animated:(BOOL)animated
- (UINavigationItem *)popNavigationItemAnimated:(BOOL)animated

In your custom view controller class write something like this:

self.navigationItem.leftBarButtonItem = yourButton;
self.navigationItem.rightBarButtonItem = yourSecondButton;

So you could write something like this:

[myNavBarReference pushNavigationItem:self.navigationItem animated:NO];
情泪▽动烟 2024-10-20 05:51:47

rightBarButton 是为UINavigationItem 定义的。请参阅 UINavigationItem< 的文档/code>UINavigationBar(特别是向导航栏添加内容)。

使用的方法是 - (void)pushNavigationItem:(UINavigationItem *)itemAnimated:(BOOL)animated

rightBarButton is defined for UINavigationItem. See the documentation for the UINavigationItem and for the UINavigationBar (Specially Adding Content to a Navigation Bar).

The method to use is - (void)pushNavigationItem:(UINavigationItem *)item animated:(BOOL)animated

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文