//
// ViewController.swift
// Label
//
// Created by 赵士军 on 2019/11/18.
// Copyright © 2019 赵士军. All rights reserved.
//
import UIKit
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
//按钮
self .setupBtn()
// Do any additional setup after loading the view.
}
func setupBtn() {
//初始化Btn
let testBtn = UIButton.init(type: .custom)
//设置位置大小
testBtn.frame = CGRect(x: 10, y: 10, width: 200, height: 200)
//设置标题
testBtn .setTitle("点击我", for: .normal)
//设置颜色
testBtn .setTitleColor(.red, for: .normal)
// 设置字体大小
testBtn.titleLabel?.font = .boldSystemFont(ofSize: 18)
//添加点击事件1
testBtn .addTarget(self, action: #selector(testButtonClick), for: .touchUpInside)
//事件2
testBtn .addTarget(self, action: #selector(buttonClick(_button:)), for: .touchUpInside)
//标记
testBtn.tag=18
//圆角
testBtn.layer.cornerRadius = 100
//
testBtn.clipsToBounds = true
//中心
testBtn.center = self.view.center
testBtn.layer.borderWidth = 12
testBtn.layer.borderColor = UIColor.red.cgColor
testBtn.backgroundColor = .green
self.view .addSubview(testBtn)
}
@objc func testButtonClick(){
print("点击我")
}
@objc func buttonClick(_button:UIButton){
print(String.init(format: "点击了%@---%d", _button,_button.tag))
}
/*
// MARK: - Navigation
// In a storyboard-based application, you will often want to do a little preparation before navigation
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
// Get the new view controller using segue.destination.
// Pass the selected object to the new view controller.
}
*/
}