I am trying to build UI\'s programmatically. How do I get this action working? I am developing with Swift.
Code in viewDidLoad:
over
try these..i hope it helps...
override func viewDidLoad() {
super.viewDidLoad()
let btn = UIButton()
btn.frame = CGRectMake(10, 10, 50, 50) //set frame
btn.setTitle("btn", forState: .Normal) //set button title
btn.setTitleColor(UIColor.redColor(), forState: .Normal) //set button title color
btn.backgroundColor = UIColor.greenColor() //set button background color
btn.tag = 1 // set button tag
btn.addTarget(self, action: "btnclicked:", forControlEvents: .TouchUpInside) //add button action
self.view.addSubview(btn) //add button in view
}
these is buttons click event..
func btnclicked(sender: UIButton!)
{
//write the task you want to perform on buttons click event..
}