[iOS/Swift] 알림창(Alert) 사용하는 방법

최정은·2023년 8월 25일
0

Swift

목록 보기
12/27

알림창 생성

let alert = UIAlertController(title: "비밀번호 바꾸기", message: "비밀번호를 바꾸시겠습니까?", preferredStyle: .alert)

액션 생성

let success = UIAlertAction(title: "확인", style: .default) { action in
            print("확인버튼이 눌렸습니다.")
}
        
let cancel = UIAlertAction(title: "취소", style: .default){ cancel in
            print("취소버튼이 눌렸습니다.")
}

액션 추가

alert.addAction(cancel)
alert.addAction(success)

알림창 표시

// 다음화면
present(alert, animated: true, completion: nil)
// completion => 알림창 표시되었을 때 실행되어야 할 코드

0개의 댓글