IT源码网

swift的UIbutton

flyfish 2021年02月16日 手机开发 644 0
  override func viewDidLoad() { 
        super.viewDidLoad() 
        // Do any additional setup after loading the view, typically from a nib. 
         
      
        
        let button:UIButton = UIButton(type:.custom) 
        button.frame = CGRect(x:10, y:150, width:100, height:30) 
        button.setTitle("按钮", for:.normal) 
        button.backgroundColor=UIColor.blue 
        button.setTitleColor(UIColor.white, for: .normal) 
         
        button.addTarget(self, action:#selector(click), for:.touchUpInside) 
         
      //  button.addTarget(self, action:, for: .touchUpInside) 
        self.view.addSubview(button) 
         
         
        //self.view.addSubview(label) 
    } 
 
     
    @objc func click(btn:UIButton){ 
        print("按钮呗点击了") 
        btn.backgroundColor = UIColor.green 
    }

 

评论关闭
IT源码网

微信公众号号:IT虾米 (左侧二维码扫一扫)欢迎添加!