본문 바로가기
🍎 iOS/UI

[iOS/UI] UIAlertController 글씨색바꾸기

by Fomagran 💻 2019. 12. 11.
728x90
반응형
  let alertController = UIAlertController(title: "", message: "", preferredStyle: .alert)

               let cancelAction = UIAlertAction(title: "Cancel", style: .cancel) { (action) in           // Cancel버튼 눌렀을 때 뭐할거야
               }
               alertController.addAction(cancelAction)

               let OKAction = UIAlertAction(title: "OK", style: .default) { (action) in      }
        OKAction.setValue(UIColor(displayP3Red: 162/255, green: 32/255, blue: 58/255, alpha: 1), forKey: "titleTextColor") //ok버튼 색깔입히기
        alertController.addAction(OKAction)
        cancelAction.setValue(UIColor(displayP3Red: 174/255, green: 174/255, blue: 174/255, alpha: 1), forKey: "titleTextColor") //cancel버튼 색깔입히기
        alertController.view.subviews.first?.subviews.first?.subviews.first?.backgroundColor = UIColor.white //알럴트 컨트롤러 배경색
       let attributedString = NSAttributedString(string: "Are you sure to unfollow?", attributes: [ //타이틀 폰트사이즈랑 글씨
        NSAttributedString.Key.font : UIFont.systemFont(ofSize: 17), //your font here
        NSAttributedString.Key.foregroundColor : UIColor(displayP3Red: 69/255, green: 65/255, blue: 65/255, alpha: 1) //타이틀 글씨색
        ])
        alertController.setValue(attributedString, forKey: "attributedTitle") //컨트롤러에 설정한 걸 세팅해준다.

        present(alertController, animated: true) //보여줘

이렇게 완성!

728x90
반응형

댓글