我正在尝试以编程方式构建UIView
s 。如何在Swift中使用动作函数获得UIButton
?如何以编程方式创建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
}
感谢它的工作对我来说 – 2015-04-05 07:36:18
如果sender.tag == 1 {...} – 2015-04-05 07:47:23