导航栏按钮未在 swift 3 中显示 [英] navigation bar button not showing in swift 3
本文介绍了导航栏按钮未在 swift 3 中显示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我们使用的是 xcode 8.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
推荐答案
我确实尝试了您的代码,但我得到 barButton.title 为 nil 或空,因此您可以为按钮设置图像,例如:
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)
现在您可以在 leftBarButtonItem 处看到图像.
Now you can see the image at the leftBarButtonItem.
如果您想在 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
这篇关于导航栏按钮未在 swift 3 中显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文