您的位置:首页 > 移动开发 > Swift

Swift-UIButton

2016-07-14 18:53 337 查看
// 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")

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: