iOS 7上的后退箭头

11
我需要在我的应用程序中添加一个左侧的按钮项,它看起来像系统返回按钮,但不是系统返回按钮,因为它将出现在仅作为我的导航控制器堆栈的唯一视图控制器的VC上并执行我的代码。简单地编写“返回”对我来说并不好,因为我还需要显示“<”箭头。有没有一种方法可以编程方式创建这样的箭头,而不必使用具有该箭头的图像?

2
请注意,建议的重复问题是一个更古老的问题,追溯到2008年,只有一个答案适用于iOS 7。此外,这里的OP已经明确要求与那个答案所描述的解决方案不同的解决方案。让我们不要太快将其关闭为重复。 - Caleb
4个回答

11
你可以在代码中的任何位置使用任何Unicode字符。你可以在这里找到所需字符:Xcode > 编辑 > 特殊字符...。搜索箭头或后退,或浏览类别。然后将需要的字符复制粘贴到XIB对象的标题中,或像其他字符一样在setTitle或setText方法中使用。例如: enter image description here

2
在 Unicode 中,没有一个箭头看起来像背部那样(至少没有那个大小)。 - johnyu
@johnyu:请截取您期望的屏幕截图并添加到您的问题中。 - staticVoidMan
好的,我已经添加了图片。 - johnyu
@johnyu:嗯...我看到了一些,但唯一的问题是将标题设置为“〈 Back”会暴露出“〈”和“Back”之间微小的不对齐。无论如何...我会寻找更好的解决方案。 - staticVoidMan
我可能只能使用那个箭头的图像。但还是谢谢你的帮助。 - johnyu

4

试试这个:

// 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];

对这个想法点赞。以下是一些改进建议以提高代码的可读性和清晰度:(1) CGRectMake(-12, -1, 20, 30),(2) arrowLabel.font = [UIFont systemFontofSize:40],(3) MakeScale(0.65,1.25)。 - Jeff

2
考虑使用一个虚拟的 UIViewController 作为你的 UINavigationController 堆栈的根视图控制器:
 [[UINavigationController alloc] initWithRootViewController:[UIViewController new]];
 [navController pushViewController:viewController animated:NO];

然后你可以使用我的BackButtonHandler扩展来处理返回按钮的动作(如此帖子所述):

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

0

在 UIBarButtonItem 文档的常量下查看 UIBarButtonSystemItem 枚举:

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

这些是由 Apple 提供的所有按钮样式:

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

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接