Skip to content

swiftui-from-zero/SwiftUIColor

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

SwiftUIColor

For so many times, I found some nice color and hope to add to my app, I found that Color in SwiftUI does not accept the colorspace... I have to type "XXX to Color Swift" in Google and go through those the stackoverflow answers for UIColor or Swift 3 that I don't need again and again.

That's why I start this project. A file that contains intuitive initializers for Color in SwiftUI. Supporting RGBA, Hex, HSL, HSV and CMKY color space at the moment. The SwiftUIColorTest is an example to illustrate all the color space supported right now.

It works for me and hope it works for you!

Simply copy the Color.swift to your project to use them :)

RGB

// `r`, `g`, `b`, `a` in [0, 1].
Color(r: Double, g: Double, b: Double, a: Double = 1)
// `r`, `g`, `b`, `a` in [0, 255].
Color(r: Int, g: Int, b: Int, a: Int = 255)

Hex

// `hex` should start with "#". It can be 6 digit like "#ABC123" or 3 digit like "#ABC".
// When the hex string is of invalid format, the initializer will throw
// `ColorInitError.hexStringErrorFormatted`.
// It is case-insensitive, you could use "#FFFfff".
// `opacity` in [0, 1].
Color(hex: String, opacity: Double = 1) throws

HSL

// `h` is an `Angle` variable as custom.
// `s`, `l`, `opacity` in [0, 1].
Color(h: Angle, s: Double, l: Double, opacity: Double = 1)

HSV

// `h` is an `Angle` variable as custom.
// `s`, `v`, `opacity` in [0, 1].
Color(h: Angle, s: Double, v: Double, opacity: Double = 1)

CMYK

// `c`, `m`, `y`, `k`, `opacity` in [0, 1]
Color(c: Double, m: Double, y: Double, k: Double, opacity: Double = 1)

Feel free to file issues or pull requests for more color space or some other functionality relates to Color~

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages