[swift] 알림과 액션 시트 사용하기

iOS 앱을 개발할 때 사용자에게 중요한 정보를 전달하거나 사용자와 상호작용하기 위해 알림액션 시트를 사용할 수 있습니다.

알림은 사용자에게 중요한 정보를 보여줄 때 사용되며, 액션 시트는 사용자로부터 선택지나 작업을 받아들일 때 사용됩니다.

알림 표시하기

알림을 표시하기 위해서는 UIAlertController를 사용해야 합니다. 다음은 간단한 예제입니다:

let alertController = UIAlertController(title: "알림 제목", message: "알림 내용", preferredStyle: .alert)

let defaultAction = UIAlertAction(title: "확인", style: .default, handler: nil)
alertController.addAction(defaultAction)

self.present(alertController, animated: true, completion: nil)

이 예제에서는 UIAlertController를 생성하고, 제목과 내용을 설정한 후 present 메서드를 사용하여 알림을 표시하고 있습니다.

액션 시트 표시하기

액션 시트를 표시하기 위해서도 마찬가지로 UIAlertController를 사용해야 합니다. 다음은 간단한 예제입니다:

let alertController = UIAlertController(title: "액션 시트 제목", message: "액션 시트 내용", preferredStyle: .actionSheet)

let firstAction = UIAlertAction(title: "첫 번째 선택지", style: .default, handler: nil)
let secondAction = UIAlertAction(title: "두 번째 선택지", style: .default, handler: nil)
let cancelAction = UIAlertAction(title: "취소", style: .cancel, handler: nil)

alertController.addAction(firstAction)
alertController.addAction(secondAction)
alertController.addAction(cancelAction)

self.present(alertController, animated: true, completion: nil)

이 예제에서는 UIAlertController를 생성하고, 선택지와 취소 버튼을 추가한 후 present 메서드를 사용하여 액션 시트를 표시하고 있습니다.

알림과 액션 시트의 모양과 동작은 사용자 경험을 중요하게 하는 앱 개발에 있어서 중요한 부분이므로 신중하게 다루어져야 합니다.

더 많은 기능과 옵션을 활용하기 위해서는 Apple 공식 문서를 참고하시기 바랍니다.