Swift

[Swift] Alert 띄우기

응디 2021. 3. 25. 17:35
  • button 클릭 시 alert 띄우기
@IBAction func Hello(_ sender: Any){

	//제목은 Hello 내용은 My...인 alert 창 생성
	let alert = UIAlertController(title: "Hello", message: "My First App project F!!"
							,preferredStyle:.alert)

	// alert 창 아래 OK title을 가진 action 버튼이 생성됨 
	//, handler: nil 일시 클릭해도 아무일도 일어나지 않음
	let action = UIAlertAction(title:"OK", style:.default, handler: nil)
	
	// alert창에 action을 붙여줌
	alert.addAction(action)

	present(alert, animated: true, completion: nil)	

}

 

  • 결과화면