Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
279 views
in Technique[技术] by (71.8m points)

ios - How to customize the navigation back symbol and navigation back text?

This is the back icon and back text now:

image

But if I want my navigation back like this:

image

I have tried to set the back to my want icon image:

image

But it useless.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

You can hide back button text in many ways.Try this simple approach.

Step1: Goto your mainstoryBoard and click navigationBar.

Step 2: Goto Attributes Inspector under Navigation Item add a BLANK SPACE in Back Button

enter image description here

Step 3: If you want to change backButton text method is pretty much the same.

enter image description here

Update 1: If you want to use an image as a back button check this link


Update 2:

Method 2: Using custom image as a back button.

Paste below code into your detailVC and set image for your back Button.

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 32pixel size.I am not sure about the asset image size.Check with apple doc about the size class.

enter image description here

Output:

enter image description here


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...