我想用自定义图像替换后退按钮中的文本。我怎样才能用快速代码做到这一点?我不想替换整个后退栏按钮,因为我想保留返回上一个 View 的默认操作行为。我还想根据返回目的地(基于 storyboardId)的位置做一个 switch 语句,这样我就可以根据 View 显示不同的图像。
这会替换图像,但它会消除默认的后退按钮行为,我需要区分后退目标是什么,以便我可以显示正确的后退图像。
self.navigationItem.leftBarButtonItem =
UIBarButtonItem(image:StyleKit.imageOfMap, style:.Plain, target:self, action:nil);
最佳答案
尝试更改您的 leftBarButtonItem
:
self.navigationItem.leftBarButtonItem =
UIBarButtonItem(image:StyleKit.imageOfMap, style:.Plain, target:self, action:nil);
到backBarButtonItem
:
self.navigationItem.backBarButtonItem =
UIBarButtonItem(image:StyleKit.imageOfMap, style:.Plain, target:self, action:nil);
为了利用 backBarButtonItem
的默认操作。
然后将这行代码放在 View Controller 中您希望自定义后退按钮出现在其中的代码。
编辑:如果您不希望“<”符号出现在您的按钮上,您实际上必须使用 leftBarButtonItem
然后关闭 View Controller 在一个单独的方法中,例如:
self.navigationItem.leftBarButtonItem =
UIBarButtonItem(image:StyleKit.imageOfMap, style:.Plain, target:self, action:"backButtonPressed:");
}
func backButtonPressed(sender:UIButton) {
navigationController?.popViewControllerAnimated(true)
}
关于ios - 如何在 Storyboard 导航 Controller 中替换/自定义后退按钮图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28421769/