简体   繁体   中英

navigation bar button not showing in swift 3

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM