import UIKit
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
let button = UIButton(type:UIButtonType.custom)
button.frame = CGRect(x:,y:,width:,height:)
button.backgroundColor = UIColor.black
button.addTarget(self, action: #selector(buttonClick), for: .touchUpInside)
button.setTitle("测试啦", for: .normal)
button.setTitleColor(UIColor.red, for: UIControlState.normal)
button.setImage(UIImage.init(named: "54056be791853"), for: UIControlState.normal)
self.view.addSubview(button)
}
func buttonClick(button:UIButton) {
print("按钮点击了\(button.titleLabel?.text)")
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
}
}