1. 程式人生 > >iOS開發(Swift)——Button的使用

iOS開發(Swift)——Button的使用

var button = UIButton(type:UIButtonType.system)
//var button = UIButton(type:UIButtonType.custom)
//button.setImage(UIImage(named:"圖片名"), for: UIControlState.init(rawValue: 0))
        button.frame=CGRect(x:Int(screen_width-70), y:100+80*3+60, width:50, height:30)
        button.setTitle("登入", for: UIControlState.init
(rawValue: 0)) button.setTitleColor(UIColor.init(red: 236/255.0, green: 145/255.0, blue: 24/255.0, alpha: 1.0), for: UIControlState.init(rawValue: 0)) button.backgroundColor=UIColor.clear button.addTarget(self, action: #selector(self.pushToLogin), for: UIControlEvents.touchUpInside) //帶引數的寫法 //button.addTarget
(self, action:#selector(selectQuestion(_:)), for: UIControlEvents.touchUpInside) button.titleLabel?.font=UIFont.systemFont(ofSize: 12) self.view.addSubview(button) func pushToLogin(){ } //帶引數的寫法 //func selectQuestion(_ sender:UIButton){ }