Swift学习之UIButton

来源:互联网 发布:淘宝充话费多久到账 编辑:程序博客网 时间:2024/04/29 20:49

定义一个不可变的button以及触发方法的实现

        //创建一个button

        let button:UIButton =UIButton(type: .Custom)

        //设置位置以及大小

        button.frame =CGRectMake(10,150,100,30)

        button.setTitle("普通状态", forState:UIControlState.Normal)

        button.setTitle("触摸状态", forState:UIControlState.Highlighted)

        button.setTitle("禁用状态", forState:UIControlState.Disabled)

        //设置点击触发的方法

        button.addTarget(self, action:Selector("clickButtonAction:"), forControlEvents: .TouchUpInside)

        self.view.addSubview(button);


点击触发的方法实现

          func clickButtonAction:() {

                  print("点击我了")

          }

0 0
原创粉丝点击