[英]How to customize the navigation back symbol and navigation back text?
This is the back icon and back text now: 现在是后退图标和后退文本:
But if I want my navigation back like this: 但是,如果我想像这样导航:
I have tried to set the back to my want icon image: 我试图将背面设置为我想要的图标图像:
But it useless. 但这没用。
You can hide back button text in many ways.Try this simple approach. 您可以通过多种方式隐藏后退按钮文本。尝试这种简单方法。
Step1: Goto your mainstoryBoard
and click navigationBar
. 第1
mainstoryBoard
:转到您的mainstoryBoard
并单击navigationBar
。
Step 2: Goto Attributes Inspector
under Navigation Item
add a BLANK SPACE in Back Button
第2步:在“
Navigation Item
下的“转到Attributes Inspector
,在“ Back Button
添加空白空间
Step 3: If you want to change backButton
text method is pretty much the same. 步骤3:如果要更改
backButton
文本方法几乎相同。
Update 1: If you want to use an image as a back button check this link 更新1:如果您要将图像用作后退按钮,请选中此链接
Update 2: 更新2:
Method 2: Using custom image as a back button. 方法2:使用自定义图像作为后退按钮。
Paste below code into your detailVC
and set image for your back Button. 将以下代码粘贴到
detailVC
并为后退按钮设置图像。
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
title = "Detail VC"
let customButton = UIBarButtonItem(image: UIImage(named: "back"), style: .plain, target: self, action: #selector(backButtonTapped)) //
self.navigationItem.leftBarButtonItem = customButton
}
func backButtonTapped() {
_ = navigationController?.popToRootViewController(animated: true)
}
I am setting back button image in assets catalogue
with the 32
pixel size.I am not sure about the asset image size.Check with apple doc
about the size class. 我在
assets catalogue
设置了32
像素大小的后退按钮图像。我不确定资产图像的大小。请与apple doc
有关大小类的信息。
Output: 输出:
Create a new UIBarButton
and add it the navigationItem.leftBarButton
. 创建一个新的
UIBarButton
并将其添加到navigationItem.leftBarButton
。
let backButton = UIBarButtonItem(image: UIImage(named:"yourImage"), style: .plain, target: self, action: #selector(yourBackMethod(sender:))
navigationItem.leftBarButtonItem = = backButton
@objc internal func yourBackMethod(sender: AnyObject) {
navigationController.popViewController()
}
Hope this helps. 希望这可以帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.