close

Take notes for self...(swift 4.0)

使用@IBAction關鍵字,讓程式與使用者介面做連結

  @IBAction func showMessage() {

        //todo something...

    }

 

 @IBAction func showMessage(sender: UIButton) {

        //todo something...

    }

 

[Other Notes]

● Swift is a lot like C#

SWIFT

func goodDay(name: String, day: String) -> String {

return "Hello \(name), today is \(day)."

}

goodDay("Riva", "Tuesday")

 

C#

public string GoodDay(string name, string day) {

return $"Hello {name}, today is {day}.";

}

GoodDay("Riva", "Tuesday");

 

 ● Alert Message
//方便自己Copy

 //aler message

 let alertMsg= UIAlertController(title: "Welcome...", message: "Hi~", preferredStyle: UIAlertControllerStyle.alert)

 alertMsg.addAction(UIAlertAction(title: "OK", style: UIAlertActionStyle.default, handler: nil))

 self.present(alertMsg, animated: true, completion: nil)}

//有註解

 //aler message: 使用 UIAlertController來建立welcom...訊息 

 let alertController= UIAlertController(title: "Welcome...", message: "Hi~", preferredStyle: UIAlertControllerStyle.alert)//建立UIAlertController物件

 alertController.addAction(UIAlertAction(title: "OK", style: UIAlertActionStyle.default, handler: nil))//呼叫addAction方法來加入動作: 顯示「OK」按鈕提示

 self.present(alertController, animated: true, completion: nil)} //使用self屬性 在畫面顯示訊息。self可以省略 => present(alert, animated: true, complection: nil)

 

arrow
arrow

    以戒為師 發表在 痞客邦 留言(0) 人氣()