标签:
// let bt = UIButton(frame:CGRectMake(10,20,50,50))
let button = UIButton(frame:CGRectMake(10, 150, 100, 30)) //初始化按钮和设置按钮位置与大小
button.backgroundColor = UIColor.grayColor() //设置按钮的背景颜色
//button.setTitle("确定", forState: UIControlState.Normal) //普通状态下的文字
button.setTitle("确定", forState: UIControlState.Highlighted) //点击状态下显示文字
button.setTitleColor(UIColor.redColor(), forState: UIControlState.Normal) //设置按钮文字的颜色
button.setImage(UIImage(named: "1"), forState: .Normal) //设置按钮的背景图片
button.addTarget(self, action: #selector(tapped(_:)), forControlEvents: UIControlEvents.TouchUpInside) //按钮的触发事件
self.view.addSubview(button)
func tapped(bt:UIButton) {
print("1231313")
}
标签:
原文地址:http://www.cnblogs.com/lcl15/p/5671440.html