[英]The UIButton on UIToolBar seems to be not working
這是我的代碼
override func viewDidLoad() {
super.viewDidLoad()
let button1 = UIButton(frame: CGRect(x: 50, y: 50, width: 30, height: 30))
button1.setTitle("hi", for: .normal)
button1.setTitleColor(.blue, for: .normal)
button1.setTitleColor(.black, for: .highlighted)
button1.addTarget(self, action: #selector(self.barItem2Clicked(sender:)), for: .touchUpInside)
button1.backgroundColor=UIColor.red
let barButton1 = UIBarButtonItem(customView: button1)
toolBar1.items?.append(barButton1)
}
方法barItem2Clicked
:
func barItem2Clicked(sender :Any?) {
NSLog("hello")
}
我想使用UIButton添加到UIToolBar,但是無法調用button1
的動作,也不會顯示“突出顯示”效果。
我單擊了剛剛添加的button1
,但是從未調用過barItem2Clicked
方法。
我錯過了什么嗎?
謝謝
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.