自定义导航控制器的后退按钮

发布于 2024-09-10 03:23:37 字数 98 浏览 4 评论 0原文

我想在导航栏的左侧有两个按钮,一个是常规后退按钮,另一个是 UIBarButtonItem。但是我只能用它来替换默认的后退按钮。我在互联网上尝试了许多代码示例,但无法正常工作。请帮忙

I want to have two buttons on the left side of the navigation bar, one is the regular back button and the other one is a UIBarButtonItem. However I could only get it to replace the default back button. I've tried many code samples on the internet but couldn't get any to work. please help

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

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

发布评论

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

评论(4

歌入人心 2024-09-17 03:23:37

不要这样做。它违反了 Apple 提出的 UI 准则。 请参阅 iPhone HIG 图 6-6 之前的段落

Don't do this. It breaks the UI guidelines put forth by Apple. See the paragraph right before figure 6-6 of the iPhone HIG.

夏九 2024-09-17 03:23:37

据我所知,(目前)不可能在 UINavigationBar 的两侧有两个 UIBarButtonItems

As far as I'm aware it's not (currently) possible to have two UIBarButtonItems on either side of a UINavigationBar.

迷途知返 2024-09-17 03:23:37

为此,您必须将 UIToolBar 用于导航控制器上的多个按钮

For this you have to use the UIToolBar for multiple buttons on navigation controller

月亮邮递员 2024-09-17 03:23:37

是的,你可以通过以下方式做到这一点:

UIButton *backBtn = [UIButton buttonWithType:UIButtonTypeCustom];  
UIImage *homeImage = [UIImage imageNamed:@"YOUR_IMAGE.png"];  
[backBtn setBackgroundImage:homeImage forState:UIControlStateNormal];  
[backBtn addTarget:self action:@selector(YOUR_ACTION)  
forControlEvents:UIControlEventTouchUpInside];  
backBtn.frame = CGRectMake(0, 0, 69, 26);  
UIBarButtonItem *button1 = [[UIBarButtonItem alloc] initWithCustomView:backBtn];
[[self navigationItem] setLeftBarButtonItem:button1];
[button1 release];
button1 = nil;

Yes you can do this by-

UIButton *backBtn = [UIButton buttonWithType:UIButtonTypeCustom];  
UIImage *homeImage = [UIImage imageNamed:@"YOUR_IMAGE.png"];  
[backBtn setBackgroundImage:homeImage forState:UIControlStateNormal];  
[backBtn addTarget:self action:@selector(YOUR_ACTION)  
forControlEvents:UIControlEventTouchUpInside];  
backBtn.frame = CGRectMake(0, 0, 69, 26);  
UIBarButtonItem *button1 = [[UIBarButtonItem alloc] initWithCustomView:backBtn];
[[self navigationItem] setLeftBarButtonItem:button1];
[button1 release];
button1 = nil;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文