[swift] PMAlertController 알림창 프로그레스바 추가하기

PMAlertController는 iOS에서 사용되는 커스텀 알림창 라이브러리입니다. 이 라이브러리는 간편하게 다양한 종류의 알림창을 만들 수 있도록 도와줍니다.

하지만 기본적으로 제공되는 기능 외에 추가적인 UI 요소를 사용하려면 몇 가지 작업을 해야합니다. 이번 글에서는 PMAlertController에 프로그레스바를 추가하는 방법에 대해 알아보겠습니다.

필수 라이브러리 설치

PMAlertController 라이브러리는 CocoaPods를 통해 설치할 수 있습니다. Podfile을 열고 다음과 같이 라이브러리를 추가해주세요.

pod 'PMAlertController'

설치가 완료되면 Xcode 프로젝트를 다시 빌드해야합니다.

프로그레스바 추가하기

import PMAlertController

class ViewController: UIViewController {

    // 알림창을 띄우는 버튼 액션
    @IBAction func showAlert(_ sender: Any) {
        let alert = PMAlertController(title: "알림", description: "작업 진행중입니다.", image: UIImage(named: "info_icon.png"), style: .alert)

        // 프로그레스바 추가
        let progressView = UIProgressView(frame: CGRect(x: 0, y: 0, width: 200, height: 20))
        progressView.progress = 0.5
        progressView.tintColor = UIColor.blue
        alert.view.addSubview(progressView)
        
        // 알림창 표시
        self.present(alert, animated: true, completion: nil)
    }
}

showAlert 액션 메서드 내부에서 PMAlertController 객체를 생성합니다. 그리고 UIProgressView 인스턴스를 만들어 알림창의 서브뷰로 추가해줍니다. progress 속성을 사용하여 프로그레스바의 진행 상태를 설정할 수 있습니다.

실행 결과

알림창 결과

위와 같이 알림창에 프로그레스바가 추가되어 표시됩니다.

결론

이제 PMAlertController를 사용해서 알림창에 프로그레스바를 추가하는 방법에 대해 알아보았습니다. 이를 활용하여 더욱 유연하고 다양한 기능을 가진 알림창을 구현할 수 있습니다.