[置顶] swift创建第一个UIButton 并增加点击事件


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的点击事件")
    }

你可能感兴趣的:(ios,swift,UIButton)