我在导航栏中有一个以编程方式制作的导航按钮,我正在尝试在按钮上制作图像(就像后退按钮一样)并且我做了它,但我的问题是,按钮没有出现在左下角,它出现了在一些空间之后。
let button = UIButton(type: .system)
button.frame = CGRect(x: 0, y: 0, width: 10, height: 40)
button.setTitle("Back", for: .normal)
button.setImage(UIImage(named: "ic_keyboard_arrow_left_2x"), for: .normal)
let barButton = UIBarButtonItem(customView: button)
self.navigationItem.leftBarButtonItems = [barButton]
请帮助我完成任务
答案 0 :(得分:0)
将所有代码替换为:
self.navigationItem.backBarButtonItem = UIBarButtonItem(image: UIImage(named: "ic_keyboard_arrow_left_2x"), style: .plain, target: self, action: #selector(yourSelector))
self.navigationController?.navigationBar.topItem?.title = "Back"