Dark mode support and adaptive colors

11914
0

Dark mode provides low-light interface that reduces eye strain and saves battery on OLED displays. iOS automatically switches based on system settings or user preference. I use semantic colors like .label, .secondaryLabel, and .systemBackground that adapt automatically. For custom colors, I create color assets in Asset Catalog with light and dark variants. UIColor(named:) loads adaptive colors. In SwiftUI, Color initializers like Color("MyColor") work similarly. I test both modes using environment overrides or Xcode's appearance selector. Images can have dark variants using asset catalogs. The .preferredColorScheme() modifier forces a specific mode. Respecting user's appearance choice is important for accessibility and battery life.