ios后退button在酒吧

可以在工具栏中插入一个工具button,其形状与导航栏中使用的后退button相似? 这里是我的意思:

样品

提前致谢!

你不能这样做,至less不是后退button的形状,箭头在左边。 backBarButtonItem只是UINavigationItem的一个属性。

您可以使用工具栏上的矩形button返回(尽pipe我不认为苹果公司喜欢这一点…您应该阅读iOS人机界面指南),

或者您可以在屏幕上的其他位置添加自定义后退button。 例如,如果您的工具栏位于底部,您可以在屏幕的左上angular添加一个自定义后退button,以保持整洁。 这样,您将保存具有仅用于后退button的导航栏的屏幕空间。

typeonerror在github上包含你所需要的代码; 它实际上是在视图控制器上自定义后退button,但是您可以使用它在工具栏上创build后退button:

https://github.com/typeoneerror/BBCustomBackButtonViewController

特别是像下面的代码(实际上来自于stackoverflow, UINavigationBar的自定义和后退button ):

 + (UIBarButtonItem *)styledBackBarButtonItemWithTarget:(id)target selector:(SEL)selector; { UIImage *image = [UIImage imageNamed:@"button_back"]; image = [image stretchableImageWithLeftCapWidth:20.0f topCapHeight:20.0f]; NSString *title = NSLocalizedString(@"Back", nil); UIFont *font = [UIFont boldSystemFontOfSize:12.0f]; UIButton *button = [UIButton styledButtonWithBackgroundImage:image font:font title:title target:target selector:selector]; button.titleLabel.textColor = [UIColor blackColor]; CGSize textSize = [title sizeWithFont:font]; CGFloat margin = (button.frame.size.height - textSize.height) / 2; CGFloat marginRight = 7.0f; CGFloat marginLeft = button.frame.size.width - textSize.width - marginRight; [button setTitleEdgeInsets:UIEdgeInsetsMake(margin, marginLeft, margin, marginRight)]; [button setTitleColor:[UIColor colorWithRed:53.0f/255.0f green:77.0f/255.0f blue:99.0f/255.0f alpha:1.0f] forState:UIControlStateNormal]; return [[[UIBarButtonItem alloc] initWithCustomView:button] autorelease]; }