var button1 = UIButton(frame: CGRectMake(100,200,100,40)) button1 .setTitle("first button",forState:UIControlState.Normal) button1.addTarget(self,action: "firstSwift:",forControlEvents: UIControlEvents.TouchUpInside) self.view.addSubview(button1) button1.backgroundColor=UIColor.yellowColor() button1.setTitleColor(UIColor.blackColor(),forState: UIControlState.Normal) func firstSwift(sender:UIButton) { println("第一个button的点击事件") }