美文网首页
Swift中UIButton写法

Swift中UIButton写法

作者: 我一不小心就 | 来源:发表于2019-01-28 15:41 被阅读0次
override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view, typically from a nib.
        
        let testBtn:UIButton = UIButton(type: .custom)
        testBtn.frame = CGRect(x: 0, y: 600, width: 200.0, height: 30.0)
        testBtn.setTitle("登陆", for: .normal)
        testBtn.setTitleColor(UIColor.lightGray, for: .normal)
        testBtn.tag = 101
        
        //
        testBtn.addTarget(self, action: #selector(testActionMethod), for: .touchUpInside)
        
        // 带参数的按钮点击事件
        // testBtn.addTarget(self, action: #selector(testAction(testBtn:)), for: .touchUpInside)
        self.view.addSubview(testBtn)
    }
    
    @objc func testActionMethod(){
        print("no arguments.....")
    }
    
    @objc func testAction(testBtn:UIButton){
        print("testAction.... \(testBtn.tag)")
    }

相关文章

网友评论

      本文标题:Swift中UIButton写法

      本文链接:https://www.haomeiwen.com/subject/rkbajqtx.html