[英]The UIButton on UIToolBar seems to be not working
Here's my code 这是我的代码
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)
}
method barItem2Clicked
: 方法barItem2Clicked
:
func barItem2Clicked(sender :Any?) {
NSLog("hello")
}
I wanted to use UIButton add to UIToolBar, but the action of button1
can not be called, and the Highlighted effect is not shown too. 我想使用UIButton添加到UIToolBar,但是无法调用button1
的动作,也不会显示“突出显示”效果。
I clicked the button1
I just added, but the method barItem2Clicked
never called. 我单击了刚刚添加的button1
,但是从未调用过barItem2Clicked
方法。
Did I missed something? 我错过了什么吗?
Thanks 谢谢
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.