Swift UIButton


        let button = UIButton(type:.system);
        button.frame = CGRect.init(x:100,y:150,width: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("按钮被点击了");
    }

posted @ 2017-10-17 12:05  朝阳向日葵  阅读(219)  评论(0编辑  收藏  举报