Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/divadretlaw/crayon
🎨 Color Utility
https://github.com/divadretlaw/crayon
Last synced: 14 days ago
JSON representation
🎨 Color Utility
- Host: GitHub
- URL: https://github.com/divadretlaw/crayon
- Owner: divadretlaw
- License: mit
- Created: 2022-04-14T19:45:39.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2024-03-30T08:44:52.000Z (8 months ago)
- Last Synced: 2024-10-03T02:15:34.504Z (about 1 month ago)
- Language: Swift
- Homepage:
- Size: 47.9 KB
- Stars: 1
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Crayon
[![](https://img.shields.io/endpoint?url=https%3A%2F%2Fswiftpackageindex.com%2Fapi%2Fpackages%2Fdivadretlaw%2FCrayon%2Fbadge%3Ftype%3Dplatforms)](https://swiftpackageindex.com/divadretlaw/Crayon)
[![](https://img.shields.io/endpoint?url=https%3A%2F%2Fswiftpackageindex.com%2Fapi%2Fpackages%2Fdivadretlaw%2FCrayon%2Fbadge%3Ftype%3Dswift-versions)](https://swiftpackageindex.com/divadretlaw/Crayon)## Usage
In the example SwiftUI `Color` is used but it also works with `UIColor`, `NSColor` and `CGColor`.
### Init
```swift
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
```swift
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
```swift
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`
```swift
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
```swift
Color(.red) + Color(.green) = Color(.yellow)
Color(.yellow) - Color(.red) = Color(.green)
```## Install
### SwiftPM
```
https://github.com/divadretlaw/Crayon.git
```## License
See [LICENSE](LICENSE)
Copyright © 2022 David Walter (www.davidwalter.at)