swift的UIbutton

  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
    }

 

posted @ 2018-02-23 10:03  layfork  阅读(101)  评论(0编辑  收藏  举报