定义一个不可变的button以及触发方法的实现
//创建一个button
let button:UIButton =UIButton(type: .Custom)
//设置位置以及大小
button.frame =CGRectMake(10,150, 100,30)
button.setTitle("普通状态", forState:UIControlState.Normal)
button.setTitle("触摸状态", forState:UIControlState.Highlighted)
button.setTitle("禁用状态", forState:UIControlState.Disabled)
//设置点击触发的方法
button.addTarget(self, action:Selector("clickButtonAction:"), forControlEvents: .TouchUpInside)
self.view.addSubview(button);
点击触发的方法实现
func clickButtonAction:() {
print("点击我了")
}