leftbarbuttonitem does not show up in the navigation bar

前端 未结 7 1708
Happy的楠姐
Happy的楠姐 2021-01-17 10:07

I\'ve been developing an iOS app and have been having issues with using an image as the left bar button item in the navigation bar. I have attempted this in the following wa

7条回答
  •  悲&欢浪女
    2021-01-17 10:29

    Calling myButton.sizeToFit() before assigning to leftBarButtonItem helped me.

        let cancelButton = UIButton()
        cancelButton.backgroundColor = .red
        cancelButton.setTitle("Common/Cancel".localized, for: .normal)
        cancelButton.sizeToFit() //!!!
        let cancelBarButton = UIBarButtonItem(customView: cancelButton)
        navigationItem.leftBarButtonItem = cancelBarButton
    

提交回复
热议问题