-
[iOS] 알림창(UIAlertController) 색상 변경iOS 2023. 9. 28. 20:06
아래처럼 기존 알림창의 색깔과는 다른 색을 지정해줘야할때가 있다! 그렇다면 어떻게 색상을 변경할 수 있을깡?


1. 알림창 띄우기
알림창 자체를 띄우는 방법은 간단하다!
let alert = UIAlertController(title: "", message: "", preferredStyle: .alert)위와 같이 알림창을 정의해주고, 아래처럼 버튼을 지정해주면 된다. (confirm 버튼만 있으니까, 이건 "확인" 버튼만 있는 첫번째 이미지처럼 나온다!)
let confirm = UIAlertAction(title: "확인", style: .default) { (action) in switch stat { case -1: self.ServerError() case 2000: print("문의사항 요청성공") case 4000: print("문의사항 존재안하는 이메일") default: print("문의사항 디비 저장 오류") } self.navigationController?.popViewController(animated: true) }; alert.addAction(confirm)2. 색상 변경
confirm.setValue(UIColor(red: 0.563, green: 0.691, blue: 0.883, alpha: 1), forKey: "titleTextColor") alert.view.subviews.first?.subviews.first?.subviews.first?.backgroundColor = UIColor(red: 0, green: 0, blue: 0, alpha: 0.7) let attributedString = NSAttributedString(string: "문의사항 보내기 완료되었습니다.\n감사합니다.", attributes: [ NSAttributedString.Key.font : UIFont.systemFont(ofSize: 16), NSAttributedString.Key.foregroundColor : UIColor(red: 1, green: 1, blue: 1, alpha: 1)]) alert.setValue(attributedString, forKey: "attributedTitle") //컨트롤러에 설정한 걸 세팅 present(alert, animated: true, completion: nil)setValue로 confirm text 색상을 변경해주고, 배경색도 변경해준다! 그리고 alert 컨트롤러에 변경한 내용을 세팅해주면 된다~!
attributedString = NSAttributedString(string: "문의사항 보내기 완료되었습니다.\n감사합니다.", attributes: [ NSAttributedString.Key.font : UIFont.systemFont(ofSize: 16), NSAttributedString.Key.foregroundColor : UIColor(red: 1, green: 1, blue: 1, alpha: 1)])마지막 present는 파라미터로 UIAlertAction객체가 바인딩된 UIAlertController객체를 넘겨주는 것이다!
[iOS] 알림창 띄우기 (alert) - UIAlertController
요즘 소셜로그인 구현을 해보는 중인데 다들 앱 사용하시다 보면 이런 창 많이 보셨나요!? alert라고도 불리며, 정확한 명칭은 UIAlertController인데요! 오늘은 alert 메시지 박스 띄우는 걸 구현해 보
peppo.tistory.com
https://zeddios.tistory.com/111
iOS ) 왕초보를 위한 Alert View사용해보기 (2/3)
저번시간에 Alert에 대해서 이론적인? 설명만을 했는데, 오늘은 직접 써보는 시간을 가질거에요 :)간단하게 어떤 버튼을 누르면 딱!!하고 Alert View가 나타나는 그런 간단한 앱을 만들어볼게요. 어
zeddios.tistory.com
https://fomaios.tistory.com/entry/AlertController
[iOS/UI] UIAlertController 글씨색바꾸기
let alertController = UIAlertController(title: "", message: "", preferredStyle: .alert) let cancelAction = UIAlertAction(title: "Cancel", style: .cancel) { (action) in // Cancel버튼 눌렀을 때 뭐할거야 } alertController.addAction(cancelAction) let
fomaios.tistory.com
'iOS' 카테고리의 다른 글
[iOS] CollectionView로 CardList 만들기 (0) 2023.09.28 [iOS] Snapkit을 이용한 UI 구성 (0) 2023.09.28 [iOS] TextField 글자수를 제한해보자! (0) 2023.09.28 [iOS] TextView PlaceHolder 추가하기 (0) 2023.09.28 [iOS] UIView 특정 모서리 둥글게 만들기 및 그림자 효과주기 (0) 2023.09.28