Swiftpack.co - SpectralDragon/PublishColorUtils as Swift Package

Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
See all packages published by SpectralDragon.
SpectralDragon/PublishColorUtils 0.1.0
A cross-platform color object. Generate css and hex representation of color
⭐️ 0
🕓 3 years ago
.package(url: "https://github.com/SpectralDragon/PublishColorUtils.git", from: "0.1.0")

PublishColorUtils

A cross-platfrom color object, can generate Hex and CSS representation of color.

Usage

You can instantiate your color object using hex or RGBA/sRGBA component values.

Color(red: 255/255, green: 255/255, blue: 255/255, alpha: 1)

Color(hex: "#ff00ff")

Color(displayP3Red: 255/255, green: 255/255, blue: 255/255, alpha: 1)

Hex and CSS representation

To get a hex representation or hex with alpha, just call:

let color = Color(red: 255/255, green: 0/255, blue: 255/255, alpha: 1)

color.hex // #FF00FF

color.hexWithAlpha // #FF00FFFF

If you need a css representation of color:

// RGB 
let color = Color(red: 255/255, green: 0/255, blue: 255/255, alpha: 1)

color.rgbaDescription // rgba(255, 0, 255, 1)

/// sRGB

let p3Color = Color(displayP3Red: 255/255, green: 0/255, blue: 255/255, alpha: 1)

p3Color.rgbaDescription // color(display-p3 1 0 1 / 1)

Dark mode

Also, this color supports dark mode:

let color = Color(hex: "#efefef").adaptiveToDarkTheme(Color(hex: "#111111"))
color.dark.hex // #111111

iOS Colors

We also supports iOS 13 system colors


Color.red == UIColor.systemRed

Color.pink == UIColor.systemPink

GitHub

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

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