Swiftpack.co - Package - ziligy/SystemColor

SystemColor

What it is

  • Swift Structs for use with SwiftUI Views that utilize the guideline colors defined by Apple
  • Colors that automatically adjust to the users selected mode
  • An automatic detector for the device's light or dark appearance mode

Example


import SwiftUI
import SystemColor

struct PlayView: View {
    var body: some View {

        VStack {

            // color hues will automatically adjust to Dark or Light Mode
            HStack {
               Circle().foregroundColor(SystemColor.blue)
               Circle().foregroundColor(SystemColor.yellow)
               Circle().foregroundColor(SystemColor.red)
               Circle().foregroundColor(SystemColor.teal)
           }.padding()

            // You can idependently use the Darkmode detection
            Text("use Dark Mode Detector as you want")
                .accentColor(SystemColor.isDarkMode ? .white : .black)

            // you can select a hue directly by specifing its Mode
            HStack {
                Circle().foregroundColor(SystemColor.LightMode.green)
                Circle().foregroundColor(SystemColor.DarkMode.green)
                Circle().foregroundColor(SystemColor.LightMode.gray6)
                Circle().foregroundColor(SystemColor.DarkMode.gray6)
            }.padding()

        }
    }
}

Notes

  • Requires ios13
  • The DarkMode detection uses UIKit and works in the Simulator or Device but not in Previews
  • Dectection only happens when the app starts, the detector does not actively monitor the mode.

To Get SystemColor

SystemColor is available through Swift Package Manager

  • Open Xcode
  • Go to File -> Swift Packages -> Add Package Dependency...
  • Paste this Github URL (https://github.com/ziligy/SystemColor.git ) into the search bar.
  • Select the SystemColor repo from the search results.
  • Choose and click Finish.

Screenshots from Demo Project

| Dark Mode | Light Mode | | --- | --- | | | |

Github

link
Stars: 0
Help us keep the lights on

Dependencies

Used By

Total: 0

Releases

1.0.1 - Aug 4, 2019