[英]navigation bar button not showing in swift 3
We are using xcode 8.0 . 我们正在使用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: 我确实尝试了您的代码,但我得到的barButton.title为nil或为空,因此您可以为按钮设置图像,例如:
button.setImage(UIImage(named: "image_name"), for: .normal)
Now you can see the image at the leftBarButtonItem. 现在,您可以在leftBarButtonItem处看到图像。
If you want to use your custom text in the leftBarButtonItem you can use: 如果要在leftBarButtonItem中使用自定义文本,则可以使用:
let barButton = UIBarButtonItem(title: "dsfjksdf", style: .plain, target: self, action: #selector(GigDatesViewController.btnNext))
navigationItem.leftBarButtonItem = barButton
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.