Swift UIButton


        let button = UIButton(type:.system);
        button.frame = CGRect.init(x:100,y:150,160,height:30);
        button.setTitle("SwiftBtton", for: .normal);
        button.backgroundColor = UIColor.brown;
        button.titleLabel?.font = UIFont.systemFont(ofSize: 17);
        button.tintColor = UIColor.cyan;
        button.addTarget(self, action: #selector(buttonDidClick), for: .touchUpInside);
        self.view.addSubview(button);
        
    }
    func buttonDidClick() {
        print("按钮被点击了");
    }

原文地址:https://www.cnblogs.com/laolitou-ping/p/7680969.html