SwiftUI Color
2021년 12월 1일 수정
≡ 목차 (Table of Contents)
이 글은 개인적인 용도 위주로 SwiftUI에서 제공되는 Color 구조체에 관한 몇가지 정보와 팁을 정리한다.
특수한 색상 이름들
accentColor: 설정에서 지정된 하이라이트 색상clear: 투명색primarysecondary
일반적인 색상 이름들
blackbluegraygreenorangepinkpurbleredwhiteyellow
OS별 기본 색상 사용하기
예를 들어 macOS의 윈도우 기본 배경색을 쓰고 싶은데 Color 구조체는 이에 해당하는 값을 가지고 있지 않다. 이럴 때는 NSColor 의 힘을 블어야 한다. 비슷하게 iOS라면 UIColor 의 힘을 빌릴 수 있다. 아래와 같은 식이다.
public extension Color { #if os(macOS) static let background = Color(NSColor.windowBackgroundColor) static let secondaryBackground = Color(NSColor.underPageBackgroundColor) static let tertiaryBackground = Color(NSColor.controlBackgroundColor) #else static let background = Color(UIColor.systemBackground) static let secondaryBackground = Color(UIColor.secondarySystemBackground) static let tertiaryBackground = Color(UIColor.tertiarySystemBackground) #endif }
