UIBarButtonItem 设置后不高亮
UIBarButtonItem is not Highlighted after setting
我已经声明了两个 UIBarButtonItem,btnEdit 和 btnSave。最初我在 viewDidLoad 中设置 btnEdit。如果用户点击 btnEdit,我想将 btnSave 设置为 rightBarButtonItem,当点击 btnSave 时,设置 btnEdit
如右边的BarButtonItem。
它工作正常,我可以点击它,但在第一次点击后按钮变淡/不处于突出显示状态。附上图片。
我如何让它有正常的状态?
var btnEdit : UIBarButtonItem!
var btnSave : UIBarButtonItem!
@objc func btnEditTapped (){
textFieldViewNote.isEditable = true
navigationItem.rightBarButtonItem = btnSave
}
@objc func btnSaveTapped (){
textFieldViewNote.isEditable = false
navigationItem.rightBarButtonItem = btnEdit
}
override func viewDidLoad() {
super.viewDidLoad()
btnSave = UIBarButtonItem(barButtonSystemItem: .save, target: self, action: #selector(btnSaveTapped))
btnEdit = UIBarButtonItem(barButtonSystemItem: .edit, target: self, action: #selector(btnEditTapped))
navigationItem.rightBarButtonItem = btnEdit
}
After loading VC - Edit in normal state
After tapping on edit - Save btn in normal State
Edit faded tapping on save barbutton
下面是固定代码
class ViewController: UIViewController {
var btnEdit : UIBarButtonItem!
var btnSave : UIBarButtonItem!
@objc func btnEditTapped (){
btnSave = UIBarButtonItem(barButtonSystemItem: .save, target: self, action: #selector(btnSaveTapped));
navigationItem.rightBarButtonItem = btnSave
}
@objc func btnSaveTapped (){
btnEdit = UIBarButtonItem(barButtonSystemItem: .edit, target: self, action: #selector(btnEditTapped)); navigationItem.rightBarButtonItem = btnEdit
}
override func viewDidLoad() {
super.viewDidLoad()
btnSave = UIBarButtonItem(barButtonSystemItem: .save, target: self, action: #selector(btnSaveTapped))
btnEdit = UIBarButtonItem(barButtonSystemItem: .edit, target: self, action: #selector(btnEditTapped))
navigationItem.rightBarButtonItem = btnEdit
}
}
我已经声明了两个 UIBarButtonItem,btnEdit 和 btnSave。最初我在 viewDidLoad 中设置 btnEdit。如果用户点击 btnEdit,我想将 btnSave 设置为 rightBarButtonItem,当点击 btnSave 时,设置 btnEdit 如右边的BarButtonItem。
它工作正常,我可以点击它,但在第一次点击后按钮变淡/不处于突出显示状态。附上图片。 我如何让它有正常的状态?
var btnEdit : UIBarButtonItem!
var btnSave : UIBarButtonItem!
@objc func btnEditTapped (){
textFieldViewNote.isEditable = true
navigationItem.rightBarButtonItem = btnSave
}
@objc func btnSaveTapped (){
textFieldViewNote.isEditable = false
navigationItem.rightBarButtonItem = btnEdit
}
override func viewDidLoad() {
super.viewDidLoad()
btnSave = UIBarButtonItem(barButtonSystemItem: .save, target: self, action: #selector(btnSaveTapped))
btnEdit = UIBarButtonItem(barButtonSystemItem: .edit, target: self, action: #selector(btnEditTapped))
navigationItem.rightBarButtonItem = btnEdit
}
After loading VC - Edit in normal state
After tapping on edit - Save btn in normal State
Edit faded tapping on save barbutton
下面是固定代码
class ViewController: UIViewController {
var btnEdit : UIBarButtonItem!
var btnSave : UIBarButtonItem!
@objc func btnEditTapped (){
btnSave = UIBarButtonItem(barButtonSystemItem: .save, target: self, action: #selector(btnSaveTapped));
navigationItem.rightBarButtonItem = btnSave
}
@objc func btnSaveTapped (){
btnEdit = UIBarButtonItem(barButtonSystemItem: .edit, target: self, action: #selector(btnEditTapped)); navigationItem.rightBarButtonItem = btnEdit
}
override func viewDidLoad() {
super.viewDidLoad()
btnSave = UIBarButtonItem(barButtonSystemItem: .save, target: self, action: #selector(btnSaveTapped))
btnEdit = UIBarButtonItem(barButtonSystemItem: .edit, target: self, action: #selector(btnEditTapped))
navigationItem.rightBarButtonItem = btnEdit
}
}