
UITextView를 사용한 프로젝트를 진행하면서 테스트를 하면서 dark mode 대응 필요성을 느껴서 작성하는 포스팅이다.
(간단하게 끝낼 예정..ㅋㅋ)
내가 dark mode 대응이 필요했던 이유는 UITextView에 placeholder가 없어 placeholder처럼 보이도록 text를 변경하고 textColor를 변경했다.
그 과정에서 UITextView.text에 textColor가 커스텀하게 지정되면서 어떤 모드여도 커스텀하게 지정된 textColor가 적용되었다.
사용자가 text를 입력할때 textColor = black
placeholder textColor = gray
위의 textColor로 지정했을때 dark mode에서도 동일하게 지정되었다.
테스트할때 text가 써지는 과정이 보이지 않았고, dark mode 대응을 준비했다.
if #available(iOS 13, *) {
return UIColor { (traitCollection: UITraitCollection) -> UIColor in
if traitCollection.userInterfaceStyle == .dark {
return UIColor.white
} else {
return UIColor.black
}
}
} else {
return UIColor.black
}
dark 모드는 iOS13부터 적용되므로 iOS13에서만 신경써주면 된다.
userInterfaceStyle로 mode를 가져올 수 있다.
오늘은 dark mode에 대응하는 코드를 알아봤다.
UITextView의 textColor만 대응하면되서 간단하지만 앞으로 늘어나겠지..?
그럼 이만!👋