Tuesday, August 19, 2014

Button

Setup:

  1. Drag the button onto the storyboard
  2. Add handler:    
    @IBAction
     func btnClicked(btnTarget: UIButton!)
        {
            //add code here
        }
  3. On the storyboard, Right click drag from the button to yellow Viewcontroller icon and select the function btnClicked.

Text Box

Setup:

  1. Drag the control onto the storyboard
  2. @IBOutlet var txb1 : UITextField!

Set Text:

txb1.text = "asdasd"

Get Text:

var strTextFromField = txb1.text

Message Box

Display:


        var alert = UIAlertController(title: "Alert", message: "Message", preferredStyle: UIAlertControllerStyle.Alert)
        alert.addAction(UIAlertAction(title: "Click", style: UIAlertActionStyle.Default, handler: nil))

        self.presentViewController(alert, animated: true, completion: nil)


Display with Actions:

???

Label

Setup:

  1. Drag the control onto the storyboard
  2. @IBOutlet var lbl1 : UILabel!


Set Text

lbl1.text = "asdasd"

Get Text

var strTextFromLabel = lbl1.text

About this blog

This blog is for jotting down important chunks of codes and lessons that I will come across while learning Swift.