Swiftpack.co - divadretlaw/Crayon as Swift Package

Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
See all packages published by divadretlaw.
divadretlaw/Crayon v1.2.0
🎨 Color Utility
⭐️ 1
🕓 1 year ago
iOS macOS watchOS tvOS
.package(url: "https://github.com/divadretlaw/Crayon.git", from: "v1.2.0")

Crayon

Usage

In the example SwiftUI Color is used but it also works with UIColor, NSColor and CGColor.

Init

let white = Color(hex: "#FFFFFF")
let red = Color(hex: "#FF0000")
let blue = Color(hex: "#0000FF")
let green = Color(hex: "#00FF00")
let yellow = Color(hex: "#FFFF00")
let black = Color(hex: "#000000")

isDark & isLight

Check whether a color is dark or light

Color.white.isDark // false
Color.black.isDark // true
Color.white.isLight // true
Color.black.isLight // false

Calculate the contrast and check if there is good (≥ 7:1) contrast

Color.black.contrast(to: Color.white) // 21
Color.black.hasContrast(with: Color.white) // true

Convert the color via lighten, darken, saturate, desaturate, inverted and negative

Color.red.negative(withOpacity: false)
Color.red.inverted()

Color.red.saturated()
Color.red.desaturated()

Color.red.ligthened()
Color.red.darkened()

You can also do basic calculations with colors

Color(.red) + Color(.green) = Color(.yellow)
Color(.yellow) - Color(.red) = Color(.green)

Install

SwiftPM

https://github.com/divadretlaw/Crayon.git

License

See LICENSE

Copyright © 2022 David Walter (www.davidwalter.at)

GitHub

link
Stars: 1
Last commit: 3 weeks ago
Advertisement: IndiePitcher.com - Cold Email Software for Startups

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