</pre><p class="p1"><pre name="code" class="plain"> override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
let bt1 = UIButton(type: UIButtonType.InfoLight)//按钮类型
bt1.frame = CGRectMake(130, 80, 40, 40)//按钮坐标、宽高
let bt2 = UIButton(type: UIButtonType.RoundedRect)
bt2.frame = CGRectMake(130, 200, 150,44)
bt2.backgroundColor = UIColor.blackColor()//按钮背景颜色
bt2.tintColor = UIColor.whiteColor()//按钮前景颜色
bt2.setTitle("button1", forState: UIControlState.Normal)//按钮文字
bt2.addTarget(self, action: "buttonclick:", forControlEvents: UIControlEvents.TouchUpInside)//按钮监听
let bt3 = UIButton(type: UIButtonType.RoundedRect)
bt3.backgroundColor = UIColor.blackColor()
bt3.tintColor = UIColor.whiteColor()
bt3.setTitle("按钮二", forState: UIControlState.Normal)
bt3.frame = CGRectMake(130, 300, 150, 44)
bt3.layer.masksToBounds = true
bt3.layer.cornerRadius = 20 //设置圆角度数
bt3.layer.borderWidth = 3 //设置边框宽度
bt3.layer.borderColor = UIColor.lightGrayColor().CGColor //设置边框颜色
self.view.addSubview(bt1)
self.view.addSubview(bt2)
self.view.addSubview(bt3)
}
按钮控件
最新推荐文章于 2022-09-13 11:30:00 发布