Swiftpack.co - nbasham/BlackLabsSwiftUIColor as Swift Package

Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
See all packages published by nbasham.
nbasham/BlackLabsSwiftUIColor 1.06
SwiftUI Color support for hex, web color constants, random, and UIColor constants.
⭐️ 15
🕓 3 years ago
iOS macOS tvOS
.package(url: "https://github.com/nbasham/BlackLabsSwiftUIColor.git", from: "1.06")

BlackLabsSwiftUIColor

Installation

Swift Package Manager

If you are using Xcode 11 or later:

  1. Click File
  2. Swift Packages
  3. Add Package Dependency...
  4. Enter: https://github.com/nbasham/BlackLabsSwiftUIColor/

UserDefaults

Works with UIColor and Color. Color is determined at runtime. This implementation grabs the current .light/.dark color and saves it, the color being saved will loose the .light/.dark color not currently in use. UIColor uses UserDefaults.standard.uicolor(forKey) and UserDefaults.standard.uicolors(forKey) API.

let color = Color.red
UserDefaults.standard.set(color, forKey: "key")
if let savedColor: Color = UserDefaults.standard.color(forKey: "key") {
print("Loaded Color from UserDefaults: \(savedColor.hex)")
}

let colors: [Color] = [.red, .orange, .pink]
UserDefaults.standard.set(colors, forKey: "arraykey")
if let savedColors: [Color] = UserDefaults.standard.colors(forKey: "arraykey") {
print("Loaded [Color] from UserDefaults: \(savedColors.map { $0.hexWithAlpha })")
}

Example project

Example project demonstrating usage.

Readme image

GitHub

link
Stars: 15
Last commit: 2 years ago
Advertisement: IndiePitcher.com - Cold Email Software for Startups

Release Notes

Added web colors test.
3 years ago

Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics