Friday, 17 October 2014

Jogendra Singh

How create button programmatically in Swift?

UIButton programmatically with the targetAction

How create button programmatically in Swift?


override func viewDidLoad() {
    
    super.viewDidLoad()
    
    let button   = UIButton.buttonWithType(UIButtonType.System) as UIButton
    button.frame = CGRectMake(100, 100, 120, 50)
    button.backgroundColor = UIColor.greenColor()
    button.setTitle("Test Button", forState: UIControlState.Normal)
    button.addTarget(self, action: "buttonAction:", forControlEvents: UIControlEvents.TouchUpInside)
    
    self.view.addSubview(button)
}

func buttonAction(sender:UIButton!)
{
    println("Button tapped")
}

Jogendra Singh

About Jogendra Singh -

I'm Founder of Jogendra.Com. I love to share my bright ideas with the whole blogging community. I'm a good iPhone Application Developer. Apart from Blogging, I love to play Cricket and mobile games (Clash of clans).

Subscribe to this Blog via Email :