How to remove all navigationbar back button title

后端 未结 30 3289
后悔当初
后悔当初 2020-12-12 15:42

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

相关标签:
30条回答
  • 2020-12-12 15:52

    You can use xcode 8 and swift 3.0

    self.navigationController?.navigationBar.backItem?.title = " "
    
    0 讨论(0)
  • 2020-12-12 15:52

    Swift 4.2

    UIBarButtonItem.appearance().setTitleTextAttributes([.foregroundColor: UIColor.clear], for: .normal)
    
    0 讨论(0)
  • 2020-12-12 15:52

    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)
    
    0 讨论(0)
  • 2020-12-12 15:52

    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)
        }
    
    0 讨论(0)
  • 2020-12-12 15:54

    I have found a simple solution:-

    at PersingtingViewController's viewWillDisappear method jsut put

    self.title = ""
    

    and set title for PersingtingViewController's on viewWillAppear method. And repeat this for all viewControllers of navigationStack except for last one.

    0 讨论(0)
  • 2020-12-12 15:56

    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)
    
    0 讨论(0)
提交回复
热议问题