2013-12-19 57 views
11

我需要在我的应用程序中添加一个看起来像系统后退按钮的左栏按钮项,但不是系统后退按钮,因为它会出现在视图控制器上,这是唯一的vc我的navController的堆栈并执行我自己的代码。简单地写“返回”对我来说并不好,因为我需要显示“<”箭头。有没有办法以编程方式创建一个这样的箭头,而没有使用该箭头形象?下的UIBarButtonItem文档中contantsiOS 7上的背向箭头

This is how it's supposed to look like

+0

可能重复[创建在UIToolbar上左箭头按钮(就像UINavigationBar的“后退”风格)](http://stackoverflow.com/questions/227078/creating-a-left-arrow-button-like-uinavigationbars-back-style-on-a -uitoolba) –

+2

请注意,建议的重复是一个更老的问题,约会到2008年,只有[一个答案](http://stackoverflow.com/a/18874211/643383)与iOS 7相关。此外,OP在这里特别提出为解决方案不同于那一个答案中描述的解决方案。让我们不要太快把它作为一个副本来关闭它。 – Caleb

回答

2

考虑使用虚拟UIViewController作为根鉴于您的UINavigationController的栈控制器:

[[UINavigationController alloc] initWithRootViewController:[UIViewController new]]; 
[navController pushViewController:viewController animated:NO]; 

然后你可以使用我BackButtonHandler扩展处理后退按钮的动作(如this thread描述):

-(BOOL) navigationShouldPopOnBackButton { 
     [self dismissModalViewControllerAnimated:YES]; 
     return NO; 
} 
0

看那UIBarButtonSystemItem枚举:

https://developer.apple.com/library/IOs/documentation/UIKit/Reference/UIBarButtonItem_Class/Reference/Reference.html#//apple_ref/doc/uid/TP40007519-CH3-SW2

这些都是由苹果公司提供的按钮样式:

typedef enum { 
    UIBarButtonSystemItemDone, 
    UIBarButtonSystemItemCancel, 
    UIBarButtonSystemItemEdit, 
    UIBarButtonSystemItemSave, 
    UIBarButtonSystemItemAdd, 
    UIBarButtonSystemItemFlexibleSpace, 
    UIBarButtonSystemItemFixedSpace, 
    UIBarButtonSystemItemCompose, 
    UIBarButtonSystemItemReply, 
    UIBarButtonSystemItemAction, 
    UIBarButtonSystemItemOrganize, 
    UIBarButtonSystemItemBookmarks, 
    UIBarButtonSystemItemSearch, 
    UIBarButtonSystemItemRefresh, 
    UIBarButtonSystemItemStop, 
    UIBarButtonSystemItemCamera, 
    UIBarButtonSystemItemTrash, 
    UIBarButtonSystemItemPlay, 
    UIBarButtonSystemItemPause, 
    UIBarButtonSystemItemRewind, 
    UIBarButtonSystemItemFastForward, 
    UIBarButtonSystemItemUndo,  // iOS 3.0 and later 
    UIBarButtonSystemItemRedo,  // iOS 3.0 and later 
    UIBarButtonSystemItemPageCurl, // iOS 4.0 and later 
} UIBarButtonSystemItem; 

也许倒带或撤消将足够接近你。

+2

不幸的是,它们是完全不同的东西。 – johnyu

11

对此,您可以使用任何Unicode字符(代码中的任意位置)。

你可以找到你想要的这里:

的Xcode>编辑>特殊字符...

搜索arrowback或浏览的类别。
然后复制粘贴(在XIB对象的标题,或在setTitlesetText方法像任何其他字符

东西等,其中所需要的字符: enter image description here

+2

unicode中没有箭头,看起来像后面的箭头(至少不是那种大小)。 – johnyu

+0

@johnyu:截取你期望的内容并将其添加到你的问题 – staticVoidMan

+0

好吧,我添加了图像 – johnyu

3

试试这个:

// After you create and place your backButton: 

UILabel* arrowLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 10, 20, 20)]; 
arrowLabel.text = @"<"; 
arrowLabel.textColor = [backButton titleColorForState:UIControlStateNormal]; 
arrowLabel.transform = CGAffineTransformMakeScale(1,2); 
[backButton addSubview:arrowLabel]; 

如果addSubview给你添麻烦了,请尝试

[backButton insertSubview:arrowLabel atIndex:0];