我想在UIToolbar中创建一个“后退”左箭头边框按钮。

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

我可以用按钮图像手动创建它,但我在任何地方都找不到源图像。它们有alpha通道边缘,所以截图和剪切不会得到非常通用的结果。

对于我打算使用的每种尺寸和配色方案,除了截图之外还有什么想法吗?

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

告诉我,我不需要这样做不是答案,当然也不值得赏金。


当前回答

在Xcode 5.x中使用Interface Builder很容易做到

使用对象库中的工具栏和栏按钮项 在按钮的属性检查器编辑图像部分 你的后退按钮图像

完成了!

其他回答

试试这个。我相信你不需要一个后退按钮图像来创建这样一个。

UIBarButtonItem *backButton = [[UIBarButtonItem alloc] initWithTitle:@"Back"
                                                               style:UIBarButtonItemStyleBordered
                                                              target:self
                                                              action:@selector(yourSelectorGoesHere:)];
self.navigationItem.backBarButtonItem = backButton;

这就是你所要做的:)

Unicode方法

我认为使用unicode字符来完成工作要容易得多。你可以通过谷歌Unicode三角形或Unicode箭头来查看箭头。从iOS6开始,苹果将该字符改为带有边框的表情符号字符。为了禁用边框,我添加了0xFE0E Unicode变体选择器。

NSString *backArrowString = @"\U000025C0\U0000FE0E"; //BLACK LEFT-POINTING TRIANGLE PLUS VARIATION SELECTOR

UIBarButtonItem *backBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:backArrowString style:UIBarButtonItemStylePlain target:nil action:nil];
self.navigationItem.leftButtonItem = backBarButtonItem;

代码块仅用于演示。它可以在任何接受NSString的按钮中工作。

要获得完整的字符列表,请搜索谷歌以获取Unicode字符和所需内容。这是黑色左指向三角形的入口。

结果

在Xcode 5.x中使用Interface Builder很容易做到

使用对象库中的工具栏和栏按钮项 在按钮的属性检查器编辑图像部分 你的后退按钮图像

完成了!

I'm not sure if this would work, but you could try creating a UINavigationController with the default settings to create the button, find the button in the navigation controller's subview hierarchy, call removeFromSuperview on it, destroy the navigation controller, and then add the button as a subview of your toolbar. You may also need to retain and the button before calling removeFromSuperview (and then release it after adding it as subview of your toolbar) to avoid it being deallocated during the process.

    self.navigationItem.leftBarButtonItem = self.navigationItem.backBarButtonItem;

对我有用。我使用这个当我有更多的标签,然后可以在标签栏上,和一个视图控制器从“更多”推覆leftBarButtonItem在它的viewDidLoad。