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){
}
iOS开发(Swift)——Button的使用
最新推荐文章于 2024-05-02 11:30:52 发布