Swift-创建UIButton(其他UI组件雷同)

     let button = UIButton.init(frame: CGRectMake(100, 100, 100, 100))
        button.setTitle("按钮", forState: UIControlState.Normal)
        button.backgroundColor = UIColor.redColor()
        button.addTarget(self, action:#selector(buttonClick), forControlEvents: UIControlEvents.TouchUpInside)
        button.setTitleColor(UIColor.grayColor(), forState: UIControlState.Normal)
        self.view.addSubview(button)

    //点击事件
    func buttonClick(){
          print("点击")
      }

 

posted @ 2016-08-25 16:07  J-Vijay  阅读(188)  评论(0编辑  收藏  举报