在UIToolbar上创建向左箭头按钮(如UINavigationBar的“back”样式) [英] Creating a left-arrow button (like UINavigationBar's "back" style) on a UIToolbar

查看:258
本文介绍了在UIToolbar上创建向左箭头按钮(如UINavigationBar的“back”样式)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在UIToolbar中创建一个后退左箭头bezel按钮。



据我所知,唯一的办法其中之一是将UINavigationController保留为默认设置,它为左侧栏项目使用一个。但是我没有办法找到创建一个作为一个UIBarButtonItem,所以我不能在一个标准的UIToolbar,即使他们非常相似的UINavigationBars一个。



我可以手动创建它的按钮图像,但我找不到源图像在任何地方。



我打算使用的每种尺寸和颜色方案的截图以外的任何想法?

/ p>

更新:请停止回避问题,并建议我不应该问这个问题,应该使用UINavigationBar。我的应用程序是Instapaper Pro。它只显示底部工具栏(以节省空间和最大化可读内容区域),并且我想在底部放置一个左箭头形的返回按钮。



告诉

解决方案这是一个非常有用的解决方案, div>

我使用了以下源自 http://www.teehanlax的psd .com / blog /?p = 447



http://www.chrisandtennille.com/pictures/backbutton.psd



然后我刚刚创建了一个自定义的UIView在工具栏项的customView属性中。



适合我。






编辑: 正如 PrairieHippo 指出, maralbjo 发现使用下面的简单代码可以解决这个问题在捆绑)应该结合这个答案。所以这里是额外的代码:

  //创建一个后退按钮而不是默认行为b UIBarButtonItem * backButton = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@back_arrow.png] 
style:UIBarButtonItemStyleBordered
target:self
action:@selector(backAction)

tipsDetailViewController.navigationItem.leftBarButtonItem = backButton;
[backButton release];


I'd love to create a "back" left-arrow-bezel button in a UIToolbar.

As far as I can tell, the only way to get one of these is to leave UINavigationController at default settings and it uses one for the left bar item. But there's no way I can find to create one as a UIBarButtonItem, so I can't make one in a standard UIToolbar, even though they're very similar to UINavigationBars.

I could manually create it with button images, but I can't find the source images anywhere. They have alpha-channel edges, so screenshotting and cutting won't get very versatile results.

Any ideas beyond screenshotting for every size and color scheme I intend to use?

Update: PLEASE STOP dodging the question and suggesting that I shouldn't be asking this and should be using UINavigationBar. My app is Instapaper Pro. It shows only a bottom toolbar (to save space and maximize readable content area), and I wish to put a left-arrow-shaped Back button in the bottom.

Telling me that I shouldn't need to do this is not an answer and certainly doesn't deserve a bounty.

解决方案

I used the following psd that I derived from http://www.teehanlax.com/blog/?p=447

http://www.chrisandtennille.com/pictures/backbutton.psd

I then just created a custom UIView that I use in the customView property of the toolbar item.

Works well for me.


Edit: As pointed out by PrairieHippo, maralbjo found that using the following, simple code did the trick (requires custom image in bundle) should be combined with this answer. So here is additional code:

// Creates a back button instead of default behaviour (displaying title of previous screen)
UIBarButtonItem *backButton = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"back_arrow.png"]
                                                               style:UIBarButtonItemStyleBordered
                                                              target:self
                                                              action:@selector(backAction)];

tipsDetailViewController.navigationItem.leftBarButtonItem = backButton;
[backButton release];

这篇关于在UIToolbar上创建向左箭头按钮(如UINavigationBar的“back”样式)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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