Swift: Ui Button create programmatically,
var button: UIButton = UIButton(type: .Custom)
button.frame = CGRectMake(80.0, 210.0, 160.0, 40.0)
button.addTarget(self, action: #selector(self.aMethod), forControlEvents: .TouchUpInside)
button.tag=2
button.setTitle("Hallo World", forState: .Normal)
view.addSubview(button)
func aMethod(sender: AnyObject) {
print("you clicked on button \(sender.tag)")
}