0

We are using xcode 8.0 . We are facing problem for custom navigation bar button item. Custom bar button not showing in navigation .

let button = UIButton.init(type: .custom)
        button.titleLabel?.text = "dsfjksdf"
        button.titleLabel?.textColor = UIColor.black;
        button.addTarget(self, action:#selector(GigDatesViewController.btnNext), for: UIControlEvents.touchUpInside)
        button.frame = CGRect.init(x: 0, y: 0, width: 30, height: 30)
        let barButton = UIBarButtonItem.init(customView: button)

        navigationItem.leftBarButtonItem = barButton
rmaddy
  • 314,917
  • 42
  • 532
  • 579
aafat
  • 148
  • 2
  • 19

1 Answers1

-2

I did try your code and I get barButton.title is nil or empty, so you can set image for button like:

button.setImage(UIImage(named: "image_name"), for: .normal)

Now you can see the image at the leftBarButtonItem.

If you want to use your custom text in the leftBarButtonItem you can use:

let barButton = UIBarButtonItem(title: "dsfjksdf", style: .plain, target: self, action: #selector(GigDatesViewController.btnNext))
navigationItem.leftBarButtonItem = barButton
Quoc Le
  • 416
  • 3
  • 9