UINavigationItem不显示左右barButtons

时间:2018-05-14 16:12:44

标签: ios swift

我在iPhone 6+上测试我的应用程序。我有一个导航栏,其中包括两个标签,一个左栏按钮(最初未显示)和一个右栏按钮。问题是标签显示但无论我怎么努力我都无法让它显示按钮。他们工作(如果你点击他们应该在哪里,他们按预期工作)但没有显示。 iPhone 5s(物理)和iPhone X(模拟器)上的测试正确,按钮显示。

我的代码有问题吗?

谢谢。

override func viewDidLoad() {
    super.viewDidLoad()
    webView.delegate = self
    loadWeb()

            let button = UIBarButtonItem(barButtonSystemItem: UIBarButtonSystemItem.action, target: self, action: #selector(share))
    button.tintColor = UIColor.white
    self.navigationItem.rightBarButtonItem = button


    let frameLabelURLTitle = CGRect.init(x: 25, y: 2, width: (self.navigationController?.navigationBar.frame.size.width)! - 182, height: (self.navigationController?.navigationBar.frame.size.height)! - 20)
    let frameLabelURL = CGRect.init(x: 25, y: 2 + frameLabelURLTitle.height, width: (self.navigationController?.navigationBar.frame.size.width)! - 182, height: 10)
    let viewLabel = UIView.init(frame: frameLabelURLTitle)
    labelTitleURL = UILabel.init(frame: frameLabelURLTitle)
    labelURL = UILabel.init(frame: frameLabelURL)
    labelURL.textColor = UIColor.white
    labelTitleURL.textColor = UIColor.white
    labelURL.font = UIFont.systemFont(ofSize: 13.0)
    viewLabel.addSubview(labelTitleURL)
    viewLabel.addSubview(labelURL)
    self.navigationController?.navigationBar.addSubview(viewLabel)

    loadingLabel.text = "loadingWeb".localized()
    loadingLabel.sizeToFit()
    self.navigationController?.isNavigationBarHidden = true

    self.placeHolderView.layer.insertSublayer(initGradient(bounds: self.view.bounds, isHorizontal: false), at: 0)
    self.loadingGifImageView.image = UIImage.gif(asset: "01-GIF_LOGO")

}

func webViewDidFinishLoad(_ webView: UIWebView) {
    self.placeHolderView.isHidden = true
    self.navigationController?.isNavigationBarHidden = false

    labelTitleURL.text = webView.stringByEvaluatingJavaScript(from: "document.title")
    labelURL.text = webView.request?.url?.absoluteString.components(separatedBy: "/")[2]

    self.navigationItem.leftBarButtonItem = nil

    if !(webView.request?.url?.absoluteString.contains("/blog/"))! {
        let newBackButton = UIBarButtonItem(image: UIImage(named: "bt_close")?.withRenderingMode(.alwaysOriginal), style: UIBarButtonItemStyle.plain, target: self, action: #selector(back))
        newBackButton.isEnabled = true
        print(newBackButton.style)
        self.navigationItem.setLeftBarButton(newBackButton, animated: true)
        self.navigationItem.leftBarButtonItem = newBackButton
        self.navigationItem.backBarButtonItem = newBackButton
    }
}

0 个答案:

没有答案