我用前面的NavigationController创建了一个新的ViewController。现在,我在navigationBar中获得此演示文稿。这是来自视图控制器之前的任何图像。我没有在那里设置此图像。如何将其更改为xcode中的文本?
答案 0 :(得分:1)
您可以使用ViewDidLoad
中的以下代码来实现
let imageBack = UIImage(named: "ic_back")!
let btnLeftMenu = UIButton(type: .system)
btnLeftMenu.bounds = CGRect(x: 10, y: 0, width: imageBack.size.width, height: imageBack.size.height)
btnLeftMenu.contentEdgeInsets = UIEdgeInsets(top: 0, left: 0, bottom: 0, right: 0)
// btnLeftMenu.addTarget(self, action: #selector(self.onBtnBackTap(_:)), for: .touchUpInside)
btnLeftMenu.setImage(imageBack, for: UIControl.State())
btnLeftMenu.setTitle("Cancel", for: .normal)
let leftButton = UIBarButtonItem(customView: btnLeftMenu)
self.navigationItem.leftBarButtonItem = leftButton
ic_back 是后退箭头图像的图像名称