关于学习Swift中UI相关之--UIButton

1.按钮的创建

 let button : UIButton = UIButton(type:.Custom)

2.按钮的大小

 button.frame = CGRectMake(10, 150, 100, 30)

3.按钮的背景

button.frame = CGRectMake(10, 150, 100, 30)

4.设置按钮的点击事件

  button.addTarget(self, action: Selector("tapped:"), forControlEvents:.TouchUpInside)

func tapped(button:UIButton)
    {
        print(button.titleForState(.Normal))
    }

5.按钮添加到View

 self.view.addSubview(button)

原文地址:https://www.cnblogs.com/YaoWang/p/5066679.html