[swift] NotificationBanner 알림창 버튼 색상 설정
이번 포스트에서는 Swift에서 NotificationBanner 알림창의 버튼 색상을 설정하는 방법에 대해 알아보겠습니다.
NotificationBanner는 사용자에게 메시지를 표시하고 상호작용할 수 있는 알림창을 나타내는 라이브러리입니다. 여기서 버튼 색상을 변경하고 싶다면 아래의 단계를 따라해보세요.
- NotificationBanner 라이브러리를 프로젝트에 추가합니다. Cocoapods를 통해 설치할 수 있습니다. Podfile에 다음과 같이 추가하고
pod install
명령어를 실행합니다.
pod 'NotificationBannerSwift'
- NotificationBanner를 사용하는 ViewController에서 다음과 같이 코드를 작성합니다.
import NotificationBannerSwift
class YourViewController: UIViewController {
// 기존의 알림창 코드...
func showNotificationBanner() {
let banner = FloatingNotificationBanner(title: "알림", subtitle: "새로운 메시지가 도착했습니다.", style: .info)
// 버튼 색상 설정
banner.buttonBackgroundColor = .red
banner.show(on: self)
}
}
여기서 banner.buttonBackgroundColor
를 사용하여 버튼의 색상을 변경할 수 있습니다. 위의 예시에서는 빨간색으로 버튼 색상을 설정하였습니다.
다른 색상을 사용하고 싶다면 UIColor
에서 제공하는 색상을 사용하거나, 커스텀 색상을 지정할 수도 있습니다.
이제 버튼 색상 설정 코드를 추가하면 NotificationBanner 알림창의 버튼 색상을 원하는대로 변경할 수 있습니다.
참고 자료:
- NotificationBannerSwift 라이브러리: https://github.com/Daltron/NotificationBanner
- UIColor: https://developer.apple.com/documentation/uikit/uicolor