How to remove all navigationbar back button title
Asked Answered
T

36

92

When I push a UIViewController, it has some title in back button at new UIViewController, if the title has a lot of text, It does not look good in iPhone 4s So I want to remove it.

If I add some code in prepareForSegue function, it is going to be a trouble.

Any better way to achieve this?

Tetrad answered 28/4, 2015 at 7:3 Comment(4)
you can also change the title of back button. and to go back you requires back button . so i think no need to remove back button.Stefanistefania
please inform after solving your problem.Stefanistefania
refer this answer https://mcmap.net/q/174147/-remove-text-from-back-button-keeping-the-iconAlys
there's nice article about this issue sarunw.com/posts/…Umbel
C
138

If you want back arrow so following code put into AppDelegate file into didFinishLaunchingWithOptions method.

For Objective-C

 [[UIBarButtonItem appearance] setBackButtonTitlePositionAdjustment:UIOffsetMake(0, -60) forBarMetrics:UIBarMetricsDefault];

For Swift

let BarButtonItemAppearance = UIBarButtonItem.appearance()
BarButtonItemAppearance.setTitleTextAttributes([NSForegroundColorAttributeName: UIColor.clear], for: .normal)

Another option give below.

In Objective C

self.navigationItem.backBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"" style:UIBarButtonItemStylePlain target:nil action:nil];

In Swift

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

UPDATE :

    let BarButtonItemAppearance = UIBarButtonItem.appearance()

    let attributes: [NSAttributedStringKey: Any] = [
    BarButtonItemAppearance.setTitleTextAttributes([NSForegroundColorAttributeName: UIColor.clear], for: .normal)
            NSAttributedStringKey.font: UIFont.systemFont(ofSize: 0.1),
            NSAttributedStringKey.foregroundColor: UIColor.clear]

    BarButtonItemAppearance.setTitleTextAttributes(attributes, for: .normal)
    BarButtonItemAppearance.setTitleTextAttributes(attributes, for: .highlighted)

UPDATE SWIFT 4.1 :

    let attributes = [NSAttributedStringKey.font:  UIFont(name: "Helvetica-Bold", size: 0.1)!, NSAttributedStringKey.foregroundColor: UIColor.clear]

    BarButtonItemAppearance.setTitleTextAttributes(attributes, for: .normal)
    BarButtonItemAppearance.setTitleTextAttributes(attributes, for: .highlighted)

Using Offset

UIBarButtonItem.appearance().setBackButtonTitlePositionAdjustment(UIOffsetMake(-1000, 0), for:UIBarMetrics.default)
Centralia answered 28/4, 2015 at 7:8 Comment(17)
setBackButtonTitlePositionAdjustment does not always work, when the back button title is very long, but not long enough to change to "Back", the title in the middle will move right.Tmesis
@Tmesis it's just a subject of how large your offset. you can easily replace '-60' with '-6000' and forget about this problemPackston
Just a little precision here, the title belongs to the PREVIOUS view controller. So remember to set it there, before the presentViewController or pushViewController method.Aldric
Hmm, this does doesn't work in AppDelegate. "Value of type AppDelegate has no member navigationItem"Adam
@Adam what are you doing?Centralia
I tried this: self.navigationItem.backBarButtonItem = UIBarButtonItem(title: "", style: UIBarButtonItemStyle.Plain, target: nil, action: nil)Adam
That seems to work. Is it a hack or is that the recommended approach? Thanks.Adam
@sixl I agree can't found how to set the bar button hidden app wide, so I just put the adjustment value to -999999Homophony
@Adam You should set your navigationItem in your viewController (somewhere like viewDidLoad:) instead of AppDelegate. Then it should work.Celinecelinka
Is there any NON HACKY way to to this? This seems really tricky or really not good way to hide the label to just put the position of the label away... I mean is there some way to set its text to ""??Schuman
@DominikBucher I've made a category for this behaviour which hides back button title from every where in the app which is kinda "NON HACKY" way, just add the category in your project and you're done . I strongly disagree with the solution of setting position using setBackButtonTitlePositionAdjustment:forBarMetrics: if user has enabled button shape from accessibility settings the shape will show up ending up ugly navigation bar.Exchequer
setBackButtonTitlePositionAdjustment will break your vertical alignment in iOS11Armandinaarmando
@alasker: I'm facing this issue of broken vertical alignment, do you have any better solution to hide the back title widely ? (I don't wan't to do it in every single viewcontroller of my app).Asphalt
No, sorry... in my case I only had to hide it a few times so it wasn't such a problem. I guess someone will come up with something sooner than later.. or you can turn to apple's dev forums for an answer.Armandinaarmando
@NimitParekh setBackButtonTitlePositionAdjustment not working properly in xcode 9. The offset affects not only the back button text but also back arrows position. same code works properly in xcode 8. Have u got any solution to this?Jelly
Seems like a hacky way. You can still see the "Back" text during the click on the back button.Dewayne
It affects not only back button title but also for example search controller cancel button. So be aware!, it might be better just to set the previous screen title to an empty string.Machiavellian
P
83

Work's like charm on Swift 3

self.navigationController?.navigationBar.topItem?.title = " "
Peasant answered 6/1, 2017 at 10:11 Comment(9)
This is the only one that worked when using navigationController?.pushViewController(_, animated:)Arnie
Thanks, mate. This one was the only one that worked out. Cheers.Marek
Worked for me also Swift 4Accouplement
It works. Better write an extension for UIViewController with this line.Eisenstark
@MaksimKniazev, any fix for that problem? I found the only solution to update the title again in viewWillAppear:.Saragossa
https://mcmap.net/q/224600/-how-to-remove-all-navigationbar-back-button-title better solves the problem without any side effect.Helper
this removes the title of the previous viewFatigued
if need to remove the back button title: self.navigationController?.navigationBar.backItem?.title = ""Payson
downvoting because it removes the title if a large title is enabled.Massicot
P
52

I'm using this line of code in AppDelegate file into didFinishLaunchingWithOptions method to remove the backbutton title.

Swift 2.x

let barAppearace = UIBarButtonItem.appearance()
barAppearace.setBackButtonTitlePositionAdjustment(UIOffsetMake(0, -60), forBarMetrics:UIBarMetrics.Default)

Swift 3.x

UIBarButtonItem.appearance().setBackButtonTitlePositionAdjustment(UIOffsetMake(0, -60), for:UIBarMetrics.default)

Swift 4.x

UIBarButtonItem.appearance().setTitleTextAttributes([NSAttributedStringKey.foregroundColor: UIColor.clear], for: .normal)
    UIBarButtonItem.appearance().setTitleTextAttributes([NSAttributedStringKey.foregroundColor: UIColor.clear], for: UIControlState.highlighted)
Pegu answered 14/11, 2015 at 10:49 Comment(5)
setBackButtonTitlePositionAdjustment does not always work, when the back button title is very long, but not long enough to change to "Back", the title in the middle will move right.Tmesis
It's not an ideal solution. If we set any navigation title without change the left navigation bar item's title, the title will shift right because of having left navigation bar title insets.Shallow
in iOS 11 it is break the back button position. It falls below its original positionSlit
How is that supposed to work? The text will still be accessible via VoiceOver.Intercrop
This creates problem when cancel or done barbuttonitem are not visible when presenting imagepicker or somethingHuei
R
23

Just need go to your Parent ViewController from where your other ViewControllers are dependent.

override func viewWillDisappear(animated: Bool) {
super.viewWillDisappear(true)
navigationItem.backBarButtonItem = UIBarButtonItem(title: "", style: .Plain, target: nil, action: nil)}
Runty answered 28/7, 2017 at 6:14 Comment(0)
N
19

Just copy this code in didFinishLaunchingWithOptions launchOptions

Swift 5

UIBarButtonItem.appearance().setBackButtonTitlePositionAdjustment(UIOffset(horizontal: -1000.0, vertical: 0.0), for: .default)

Swift 4

UIBarButtonItem.appearance().setBackButtonTitlePositionAdjustment(UIOffsetMake(-1000.0, 0.0), for: .default)
Numbers answered 4/7, 2018 at 14:2 Comment(1)
Not working on iOS 15, xCode 13Sixtyfour
G
17

it is simple. put a space in the title of the back button and ready. Remember that it has to be in the previous view where you want to remove the text.

enter image description here

Geer answered 26/9, 2017 at 20:2 Comment(1)
Best solution IMO. Doesn't require you to set the whole app to a specific clear style which may have the side-affect of making any text barbuttonitems disappear. Answer could be made better if it mentioned that you have to drag a navigationItem to your controller if there isn't one there.Vas
L
17

On iOS 14 is now present the backButtonDisplayMode property in UINavigationItem class. So, to remove back button title you can use

navigationItem.backButtonDisplayMode = .minimal

in the viewDidLoad func of the viewController where you want remove it.

To remove it in all navigationBar I used the swizzling technique

import UIKit

private let swizzling: (UIViewController.Type, Selector, Selector) -> Void = { forClass, originalSelector, swizzledSelector in
    if let originalMethod = class_getInstanceMethod(forClass, originalSelector), let swizzledMethod = class_getInstanceMethod(forClass, swizzledSelector) {
        let didAddMethod = class_addMethod(forClass, originalSelector, method_getImplementation(swizzledMethod), method_getTypeEncoding(swizzledMethod))
        if didAddMethod {
            class_replaceMethod(forClass, swizzledSelector, method_getImplementation(originalMethod), method_getTypeEncoding(originalMethod))
        } else {
            method_exchangeImplementations(originalMethod, swizzledMethod)
        }
    }
}

extension UIViewController {
    
    static func swizzle() {
        let originalSelector1 = #selector(viewDidLoad)
        let swizzledSelector1 = #selector(swizzled_viewDidLoad)
        swizzling(UIViewController.self, originalSelector1, swizzledSelector1)
    }
    
    @objc open func swizzled_viewDidLoad() {
        if let _ = navigationController {
            if #available(iOS 14.0, *) {
                navigationItem.backButtonDisplayMode = .minimal
            } else {
                // Fallback on earlier versions
                navigationItem.backButtonTitle = ""
            }
        }
        swizzled_viewDidLoad()
    }
}

And in application(_:didFinishLaunchingWithOptions:) call

UIViewController.swizzle()
Licensee answered 6/11, 2020 at 10:35 Comment(3)
Good to know about .minimal, but you need to set this on the nav controller that pushed the current view controller onto the stack. Unfortunately you can't just set it on the displaying view controller...Glasscock
Do I have to call the same method again inside swizzled_viewDidLoad?Tricrotic
@Tricrotic Yes, you have to call it. Swizzling exchanges method implementations, so with swizzled_viewDidLoad() you are calling the original one.Licensee
J
9

You could create a subclass for all UIViewControllers you want this behavior for, and in the subclass's viewDidLoad:

override func viewDidLoad() {
    super.viewDidLoad()
    self.navigationItem.backBarButtonItem = UIBarButtonItem(
        title: "", style: .plain, target: nil, action: nil)
}

This way, you can choose which controllers you want the behavior for, without duplicating code. I prefer my controllers to just say "Back", rather than the title of the previous controller, so I set that title here.

Jujube answered 13/1, 2017 at 13:11 Comment(0)
E
8

You can use xcode 8 and swift 3.0

self.navigationController?.navigationBar.backItem?.title = " "
Enwind answered 3/11, 2016 at 18:44 Comment(2)
Won't this remove the title from the previous view controller altogether?Curlew
Yes, it will remove the title for all ViewControllers pushed from self.navigationControllerLinsang
M
7

A method for iOS13.

let backButtonAppearance = UIBarButtonItemAppearance(style: .plain)
backButtonAppearance.normal.titleTextAttributes = [.foregroundColor: UIColor.clear]

let navigationBarAppearance = UINavigationBarAppearance()
navigationBarAppearance.backButtonAppearance = backButtonAppearance

UINavigationBar.appearance().standardAppearance = navigationBarAppearance
Mulciber answered 15/12, 2020 at 18:9 Comment(1)
Single solution that works for me on iOS 16.1.1Toluol
N
6
let barAppearace = UIBarButtonItem.appearance()
barAppearace.setBackButtonTitlePositionAdjustment(UIOffsetMake(0, -60), for:UIBarMetrics.default)

used this line of code in swift 3.0

Nicknickel answered 13/1, 2017 at 12:47 Comment(1)
will affect the cancel button for UISearchControllerThereunder
T
5

Taking inspiration from rordulu's answer here, I ended up creating a custom UINavigationController and UINavigation bar which seems to handle all cases of this tricky problem.

1) Initialise new UINavigationController with your custom UINavigationBar:

class CustomNavigationController: UINavigationController {

    convenience init() {
        self.init(navigationBarClass: CustomNavigationBar.self, toolbarClass: nil)
    }
}

2) Set the backItem.title property of the navigation bar to an empty string, every time the view lays itself out

class CustomNavigationBar: UINavigationBar {

    override func layoutSubviews() {
        backItem?.title = ""
        super.layoutSubviews()
    }
}

Now every time you use this navigation controller and bar combination, it will never have back button text! 🎉

Note: this should work fine if using storyboards also, just ensure to drop the custom navigation bar component into the view

Touched answered 22/6, 2017 at 11:27 Comment(5)
Amazing thanks so much! This is the best way to do it and should be the correct answer :)Erroneous
Just realised that this has a side-effect in that it will wipe the navigation item title completely. So when the previous view shows, it will not have a title! I will carry on my search for the perfect solution to this annoying problem.Touched
damn you are right. How could i miss that! Please tell me if you find a fix of this issue. thanksErroneous
Could you find out the perfect solution @HarryBloom?Saragossa
@Saragossa Not a perfect solution, but I found something that works. Have added a second answer here https://mcmap.net/q/224600/-how-to-remove-all-navigationbar-back-button-titleTouched
D
4

Simple Solution :

While you are pushing 2nd controller from 1st controller, put self.navigationItem.title = "" in viewWillDisappear of 1st controller. It hides back button title from 2nd controller.

Above statment hides 1st controllers title, hence when we came back we want title for 1st controller again. For that we have add title for 1st controller in viewWillAppear method of 1st controller.

Refer following methods (of 1st controller)

    override func viewWillDisappear(_ animated: Bool) {
    self.navigationItem.title = ""
}

override func viewWillAppear(_ animated: Bool) {
    self.navigationItem.title = "Title"
}
Delenadeleon answered 29/9, 2018 at 7:17 Comment(0)
D
4

Works on Swift 5:

        self.navigationItem.backBarButtonItem?.title = ""

Please note it will be effective for the next pushed view controller not the current one on the display, that's why it's very confusing!

Also, check the storyboard and select the navigation item of the previous view controller then type something in the Back Button (Inspector).

Dorris answered 6/11, 2019 at 5:39 Comment(1)
title is not a get property, check Apple documentationDorris
F
3

I usually add or change the back button in viewDidLoad of the UIViewController.

Something like that should work:

let leftButton = UIBarButtonItem(title: "Back", style:     UIBarButtonItemStyle.Plain, target: self, action: "closeView:")
self.navigationItem.leftBarButtonItem = leftButton

Don't forget to change and implement the function that it's called to close the view.

Even easier, just change the title:

self.navigationItem.leftBarButtonItem.title = "Back"
Faustofaustus answered 28/4, 2015 at 7:8 Comment(1)
This breaks iOS's built-in support for swiping left to right to navigate back, and IMHO, apps that break this are really irritating.Curlew
S
3
    if #available(iOS 14.0, *) {
        navigationItem.backButtonDisplayMode = .minimal
    } else {
        navigationItem.backBarButtonItem = UIBarButtonItem(title: "", style: .plain, target: nil, action: nil)
    }
Safari answered 3/2, 2022 at 14:45 Comment(0)
H
2

Swift 3:

self.navigationItem.backBarButtonItem = UIBarButtonItem(title:"", style:.plain, target:nil, action:nil)
Hotshot answered 13/1, 2017 at 1:23 Comment(0)
T
2

Adding a second answer here as my first only partially works. This method is less elegant in the fact that it requires calling a method in each view in the application, however it works without any side-effects.

So firstly, create a UIViewController extension class with a function to remove back button text and add a custom back button:

extension UIViewController {

func setBackButton() {
    navigationController?.navigationBar.backIndicatorImage = R.image.backArrow()
    navigationController?.navigationBar.backIndicatorTransitionMaskImage = R.image.backArrow()
    navigationItem.backBarButtonItem = UIBarButtonItem(title: " ", style: .plain, target: nil, action: nil)
}

Secondly, we can simply call out to this function in the viewDidLoad of each view controller you need it in.

Touched answered 4/3, 2018 at 10:16 Comment(0)
H
2

Swift 4.2

UIBarButtonItem.appearance().setTitleTextAttributes([.foregroundColor: UIColor.clear], for: .normal)
Hoskinson answered 8/10, 2018 at 15:10 Comment(1)
Cancel and Done button of imagepicker are disappeared in this approachHuei
S
2

Updated Answer For Swift 4.2

Working with UIAppearance is a cleaner way of solving the problem but it would cause all the UIBarButtonItem to have a clear text. An improved version of the solution could be to check if the UIBarButtonItem is contained in a UINavigationBar.

    UIBarButtonItem.appearance(whenContainedInInstancesOf: [UINavigationBar.self]).setTitleTextAttributes([NSAttributedString.Key.foregroundColor: UIColor.clear], for: .normal)
Sisak answered 18/1, 2019 at 7:37 Comment(0)
B
2

Just create extension of UIViewController with override function awakeFromNib() and make UIBarButtonItem with an empty title and give to navigation backBarButtonItem.

extension UIViewController {

  open override func awakeFromNib() {
    let backBarBtnItem = UIBarButtonItem(title: "", style: .plain, target: nil, action: nil)
    navigationItem.backBarButtonItem = backBarBtnItem
  }

}
Bannerman answered 27/9, 2019 at 6:12 Comment(0)
G
2

if you want to remove back button title when you open next screen

do this inside the function initialising and pushing a new screen:

navigationItem.backButtonTitle = ""

Full usage:

    let view = SomeView()
    let controller = UIHostingController(rootView: view)
    navigationItem.backButtonTitle = ""
    navigationController?.pushViewController(controller, animated: true)

But to customise back buttons for all navigation bars in your app you need to do this:

func setupNavBarAppearance() {
    let backButtonImage = Images.west.image.withAlignmentRectInsets(UIEdgeInsets(top: -5, left: -15, bottom: -5, right: -15))
    let backButtonAppearance = UIBarButtonItemAppearance(style: .plain)
    backButtonAppearance.normal.titleTextAttributes = [.foregroundColor: UIColor.clear]
    
    let appearance = UINavigationBarAppearance()
    appearance.titleTextAttributes = [NSAttributedString.Key.foregroundColor : UIColor.white]
    appearance.backButtonAppearance = backButtonAppearance
    appearance.setBackIndicatorImage(backButtonImage, transitionMaskImage: backButtonImage)
    
    UINavigationBar.appearance().standardAppearance = appearance
    UINavigationBar.appearance().scrollEdgeAppearance = appearance
    UINavigationBar.appearance().tintColor = .white
    UINavigationBar.appearance().isTranslucent = false
}

You can call it from your AppDelegate.swift

Grate answered 12/11, 2021 at 11:35 Comment(0)
M
1

Swift 4.2 & 5

Instead of playing with the navigation bar tint color which will have side effects if you are using image picker anytime later in your code.

Use below code:

extension UIViewController {
        open override func awakeFromNib() {
            navigationItem.backBarButtonItem = UIBarButtonItem(title: "", style: .plain, target: nil, action: nil)
    }  
}

Call it from your first ViewController:

self.awakeFromNib()
Mccauley answered 21/6, 2019 at 12:24 Comment(0)
L
1

Put the below code in any of the UIViewcontroller extension it will hide all the UIViewcontroller back text

open override func awakeFromNib() {
        navigationItem.backBarButtonItem = UIBarButtonItem(title: "", style: .plain, target: nil, action: nil)
    }
Liesa answered 27/9, 2019 at 6:38 Comment(0)
E
1

I have a simple solution for those, who don't want to use method swizzling or duplicating a similar code in different view controllers.

To remove back button title, create a UINavigationController subclass and override pushViewController(_, animated:) method:

final class CustomNavigationController: UINavigationController {

    override func pushViewController(_ viewController: UIViewController, animated: Bool) {

        super.pushViewController(viewController, animated: animated)

        let backBarButtonItem = UIBarButtonItem()
        backBarButtonItem.title = nil

        viewController.navigationItem.backBarButtonItem = backBarButtonItem
    }
}
Eponymous answered 26/11, 2019 at 16:45 Comment(0)
T
0

I don't know why but I found problem with hiding back button title in iPhone pluses but in device without plus shows correct with

leftBarButtonItem.title = ""

So I found simple way. It is set tint color to clear in NavigationBar of NavigationViewController in autolayout. It may be problem if you use icons or text tiles with tint. But in my case I don't use it as all.

Turgescent answered 4/8, 2017 at 6:20 Comment(0)
S
0

Just use this:

func removeBackButton(vc:UIViewController) {
        let button = UIButton.init(type: .custom)
        button.setImage(UIImage.init(named:""), for: .normal)
        let leftBarButton = UIBarButtonItem.init(customView: button)
        vc.navigationItem.leftBarButtonItem = leftBarButton
}

So call this method in viewDidLoad:

override func viewDidLoad() {
        super.viewDidLoad()
     removeBackButton(vc:self)
}
Selfgovernment answered 13/1, 2018 at 8:11 Comment(0)
P
0

You can add this extension to UIViewController And then call this function in every viewDidLoad() like : self.updateBackButton()

extension UIViewController {
func updateBackButton(){
    if self.navigationController != nil {
        self.navigationItem.backBarButtonItem = UIBarButtonItem(title: "", style: .done, target: self, action: nil)
    }
}}
Pectinate answered 5/4, 2018 at 7:37 Comment(0)
A
0

I would like to share a solution that works for me. Also, it can be adjusted base on your needs and requirements.

Note, in my case, I use a storyboard to specify CustomNavigationBar

Swift 4.2

class CustomNavigationBar: UINavigationBar {

    override func awakeFromNib() {
        super.awakeFromNib()
        guard let topItem = topItem else { return }
        removeBackButtonTitle(for: topItem)
    }

    override func pushItem(_ item: UINavigationItem, animated: Bool) {
        removeBackButtonTitle(for: item)
        super.pushItem(item, animated: animated)
    }

    func removeBackButtonTitle(for item: UINavigationItem) {
        item.backBarButtonItem = UIBarButtonItem()
    }
}
Anurag answered 21/12, 2018 at 14:29 Comment(0)
M
0

Works for Swift 4.2

Using the line of code in AppDelegate file into didFinishLaunchingWithOptions

    UIBarButtonItem.appearance(whenContainedInInstancesOf: [UINavigationBar.self]).setTitleTextAttributes([NSAttributedString.Key.foregroundColor: UIColor.clear], for: .normal)

    UIBarButtonItem.appearance(whenContainedInInstancesOf: [UINavigationBar.self]).setTitleTextAttributes([NSAttributedString.Key.foregroundColor: UIColor.clear], for: .highlighted)
Millsap answered 7/6, 2019 at 15:17 Comment(1)
This hides the back bar button text but unfortunately doesn't center the navigation bar titleLicensee
R
0

for swift 4,5

let BarButtonItemAppearance = UIBarButtonItem.appearance()
BarButtonItemAppearance.setTitleTextAttributes([NSForegroundColorAttributeName: UIColor.clear], for: .normal)
Resigned answered 25/9, 2019 at 13:26 Comment(0)
W
0
class NavigationController: UINavigationController {

    override func pushViewController(_ viewController: UIViewController, animated: Bool) {
        super.pushViewController(viewController, animated: animated)

        viewController.navigationItem.backButtonTitle = ""
    }
}
Weekend answered 8/4, 2021 at 19:17 Comment(0)
L
0
final class MainNavigationController: UINavigationController {
    override init(rootViewController: UIViewController) {
        super.init(rootViewController: rootViewController)
        delegate = self
    }

    @available(*, unavailable)
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
}

// MARK: UINavigationController Delegate
extension MainNavigationController: UINavigationControllerDelegate {
    func navigationController(
        _ navigationController: UINavigationController,
        willShow viewController: UIViewController,
        animated: Bool
    ) {
        viewController.navigationItem.backButtonTitle = ""
    }
}
Longsome answered 19/12, 2022 at 20:59 Comment(0)
P
0

It's very important that before pushing viewController you set back title to an empty string:

let myNextViewContorller = UIViewController()
navigationItem.backButtonTitle = ""
navigationController.push(myNextViewContorller, animated: true)
Petronilapetronilla answered 29/12, 2023 at 20:27 Comment(0)
R
-1

in viewDidLoad()

    let backBarButtonItem = UIBarButtonItem(title: nil, style: .plain, target: nil, action: nil)
    navigationItem.backBarButtonItem = backBarButtonItem
Reuven answered 2/7, 2020 at 13:55 Comment(0)
B
-4

I was not satisfied with the setBackButtonTitlePositionAdjustment solution, so here is a swift alternative to hide all back button texts throughout the applicataion:

    UIBarButtonItem.appearance().setTitleTextAttributes([NSFontAttributeName: barbuttonFont, NSForegroundColorAttributeName:UIColor.clearColor()], forState: UIControlState.Normal)
    UIBarButtonItem.appearance().setTitleTextAttributes([NSFontAttributeName: barbuttonFont, NSForegroundColorAttributeName:UIColor.clearColor()], forState: UIControlState.Highlighted)

You would have to call these from the AppDelegate in the didFinishLaunchingWithOptions func.

Appearance must be set to the .Highlighted state too to avoid texts being show when the user taps the back button.

Beitnes answered 14/6, 2016 at 14:10 Comment(1)
that will hide all other UIBarButtonItems as wellPackston

© 2022 - 2024 — McMap. All rights reserved.