我需要在我的应用程序中添加一个左侧的按钮项,它看起来像系统返回按钮,但不是系统返回按钮,因为它将出现在仅作为我的导航控制器堆栈的唯一视图控制器的VC上并执行我的代码。简单地编写“返回”对我来说并不好,因为我还需要显示“<”箭头。有没有一种方法可以编程方式创建这样的箭头,而不必使用具有该箭头的图像?
试试这个:
// 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];
[backButton insertSubview:arrowLabel atIndex:0];
UIViewController
作为你的 UINavigationController
堆栈的根视图控制器: [[UINavigationController alloc] initWithRootViewController:[UIViewController new]];
[navController pushViewController:viewController animated:NO];
然后你可以使用我的BackButtonHandler扩展来处理返回按钮的动作(如此帖子所述):
-(BOOL) navigationShouldPopOnBackButton {
[self dismissModalViewControllerAnimated:YES];
return NO;
}
在 UIBarButtonItem 文档的常量下查看 UIBarButtonSystemItem
枚举:
这些是由 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;
也许倒带或撤销对您来说已经足够接近了。