[swift] PMAlertController 알림창 폰트 설정하기

PMAlertController는 iOS 프로젝트에서 사용할 수 있는 커스텀 알림창을 만들어주는 라이브러리입니다. 이 라이브러리를 사용하여 알림창을 만들 때, 폰트를 설정하는 방법에 대해 알아보겠습니다.

폰트 설정하기

PMAlertController를 사용하여 알림창을 생성하고 폰트를 설정하기 위해서는 NSAttributedString을 사용해야 합니다. 아래의 예제 코드를 참고하십시오.

// 폰트와 스타일을 정의하는 딕셔너리 생성
let attributes: [NSAttributedString.Key: Any] = [
    .font: UIFont.systemFont(ofSize: 16), // 폰트 크기 설정
    .foregroundColor: UIColor.black // 폰트 색상 설정
]

// 알림창 메시지 생성
let message = "알림창 텍스트입니다."
let attMessage = NSAttributedString(string: message, attributes: attributes)

// PMAlertController 생성 후 메시지 설정
let alert = PMAlertController(title: "알림!", description: "", image: nil, style: .alert)
alert.attributedMessage = attMessage

위의 코드에서는 attributes라는 딕셔너리를 생성하여 폰트 크기와 색상을 설정하고, attMessage라는 NSAttributedString을 생성하여 폰트 설정을 적용하고자 하는 메시지에 적용하였습니다. 이후 PMAlertController의 attributedMessage 속성을 사용하여 설정한 폰트를 적용한 메시지를 설정합니다.

참고 자료