我有一个导航按钮,这是代码:
func barItem() {
let button = UIButton(type: .custom)
button.setTitle("Watch AR", for: .normal)
button.addTarget(self, action: #selector(openAR), for: .touchUpInside)
button.setTitleColor(.orange, for: .normal)
button.setTitleColor(.gray, for: .highlighted)
button.sizeToFit()
self.navigationItem.setRightBarButton(UIBarButtonItem(customView: button), animated: true);
}然后,我尝试在viewDidLoad方法中再添加一个导航按钮
override func viewDidLoad() {
super.viewDidLoad()
self.view.backgroundColor = .white
self.navigationController?.navigationBar.tintColor = UIColor.orange
self.navigationItem.rightBarButtonItem = UIBarButtonItem(title: "Add", style: .plain, target: self, action: #selector(savePicture))
self.barItem()
}但它不起作用,为什么?
发布于 2022-05-31 12:22:58
override func viewDidLoad() {
super.viewDidLoad()
let barButton1 = UIBarButtonItem(title: "Button 1", style: .plain, target: self, action: #selector(barButtonItem1))
let barButton2 = UIBarButtonItem(title: "Button 2", style: .plain, target: self, action: #selector(barButtonItem2))
self.navigationItem.setRightBarButtonItems([barButton1, barButton2], animated: true)
}
@objc func barButtonItem1(){
}
@objc func barButtonItem2(){
}https://stackoverflow.com/questions/72415283
复制相似问题