【发布时间】:2015-04-05 07:29:28
【问题描述】:
我正在尝试构建UIViews 以编程方式。如何在 Swift 中获得带有动作函数的UIButton?
以下代码没有任何动作:
let btn: UIButton = UIButton(frame: CGRectMake(100, 400, 100, 50))
btn.backgroundColor = UIColor.greenColor()
btn.setTitle("Click Me", forState: UIControlState.Normal)
btn.addTarget(self, action: "buttonAction:", forControlEvents: UIControlEvents.TouchUpInside)
self.view.addSubview(buttonPuzzle)
下面的选择器函数是:
func buttonAction(sender: UIButton!) {
var btnsendtag: UIButton = sender
}
【问题讨论】: