title: How to create a UIButton programmatically
body: <p>I am trying to build <code>UIView</code>s <strong>programmatically</strong>. How do I get a <code>UIButton</code> with an action function in Swift?</p>
  
  <p>The following code does not get any action:</p>
  
  <pre><code>let btn: UIButton = UIButton(frame: CGRectMake(100, 400, 100, 50))
  btn.backgroundColor = UIColor.greenColor()
  btn.setTitle("Click Me", forState: UIControlState.Normal)
  btn.addTarget(self, action: "buttonAction:", forControlEvents: UIControlEvents.TouchUpInside)
  self.view.addSubview(buttonPuzzle)
  </code></pre>
  
  <p>The following selector function is:</p>
  
  <pre><code>func buttonAction(sender: UIButton!) {
      var btnsendtag: UIButton = sender
  }
  </code></pre>