-
Alert ControllerUIKit 2020. 8. 18. 00:33
alert의 모양은 총 두가지로, Alert View와 Action Sheet 가 있습니다.
-> Action Sheet는 보통 여러 가지 선택지가 놓여져 있는 경우, 사용합니다.
extension UIViewController{ func alert(title: String = "알림", message: String){ let alert = UIAlertController(title: title, message: message, preferredStyle: .alert) let okAction = UIAlertAction(title: "확인", style: .default, handler: nil) alert.addAction(okAction) present(alert, animated: true, completion: nil) } }
guard let memo = memoTextView.text, memo.count > 0 else{ alert(message: "메모를 입력하세요") return }
위의 코드는 Alert View를 띄우기위한 코드입니다.
코드에서의 alert는 guard문에서 조건을 충족하지 않을 때, 경고 메세지 형식으로 창을 띄웁니다. 어떤 text의 길이가 0보다 작으면 alert창을 띄우고 return 합니다.
'UIKit' 카테고리의 다른 글
Hex to Color (0) 2020.08.18 Notification Example (0) 2020.08.18 Date Formatter (원하는 모습으로 날짜 출력) (0) 2020.08.17 Notification Center (0) 2020.07.04 View Controller의 생명주기 (0) 2020.07.04