2

I have the following code for letting the back button in my navigation bar stay with no text:

self.navigationController?.navigationBar.tintColor = UIColor.whiteColor()
let backItem = UIBarButtonItem(title: "", style: .Bordered, target: nil, action: nil)
    navigationItem.backBarButtonItem = backItem

This worked until i updated xCode. Now I get this error message:

'Bordered' was deprecated in iOS version 8.0: Use UIBarButtonItemStylePlain when
minimum deployment target is iOS 7.0 or later.

thanks for your help

0

2 Answers 2

4

Just set the style to plain. Like this

let backItem = UIBarButtonItem(title: "", style: .Plain, target: nil, action: nil)
navigationItem.backBarButtonItem = backItem
0
1

Be careful. This technique works on every device except for an iPhone 6/6s Plus!

The common answer to this question is thus:

self.navigationItem.backBarButtonItem = UIBarButtonItem(title: "", style: .Plain, target: nil, action: nil)

Apple's documentation says to use nil for the title instead:

self.navigationItem.backBarButtonItem = UIBarButtonItem(title: nil, style: .Plain, target: nil, action: nil)

Both techniques seem to work in all simulators and actual devices, save for the "iPhone plus". To rectify, without getting into creating your own Rects or similar cleverness, you can assign a single space to the title, as such:

self.navigationItem.backBarButtonItem = UIBarButtonItem(title: " ", style: .Plain, target: nil, action: nil)

I don't like this answer, but it does work. The answer really should be setting the title to nil, as Apple documents. I can't believe such a large company could not have tested for that!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.