- Notifications
You must be signed in to change notification settings - Fork220
🎨 Hue is the all-in-one coloring utility that you'll ever need.
License
zenangst/Hue
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
Hue is the all-in-one coloring utility that you'll ever need.
You can easily use hex colors with the
init(hex:)
convenience initializer onUIColor
. It supports the following hex formats#ffffff
,ffffff
,#fff
,fff
letwhite=UIColor(hex:"#ffffff")letblack=UIColor(hex:"#000000")letred=UIColor(hex:"#ff0000")letblue=UIColor(hex:"#0000ff")letgreen=UIColor(hex:"#00ff00")letyellow=UIColor(hex:"#ffff00")
letwhite=UIColor(hex:"#ffffff")letblack=UIColor(hex:"#000000")if white.isDarkColor{} // return falseif white.isBlackOrWhite{} // return true
.alpha
is a sugar forcolorWithAlphaComponent
, internally it does the exact same thing, think of it as alipstick for your implementation.
letcolorWithAlpha= myColor.alpha(0.75)
You can easily create gradient layers using thegradient()
method on arrays withUIColor
.As an extra bonus, you can also add a transform closure if you want to modify theCAGradientLayer
.
letgradient=[UIColor.blackColor(),UIColor.orangeColor()].gradient()letsecondGradient=[UIColor.blackColor(),UIColor.orangeColor()].gradient{ gradientin gradient.locations=[0.25,1.0]return gradient}
letimage=UIImage(named:"My Image")let(background, primary, secondary, detail)= image.colors()
You can get red, green, blue, and alpha components from any UIColor by using the (red|green|blue|alpha)Component property.
letmyColor=UIColor(hex:"#ffafc2")letmyColorBlueComponent= myColor.blueComponentletmyColorGreenComponent= myColor.greenComponentletmyColorRedComponent= myColor.redComponentletmyColorAlphaComponent= myColor.alphaComponent
letred=UIColor.redColor()letgreen=UIColor.greenColor()letyellow= red.addRGB(green)letdesaturatedBlue=UIColor(hex:"#aaaacc")letsaturatedBlue= desaturatedBlue.addHue(0.0, saturation:1.0, brightness:0.0, alpha:0.0)
If you want to support the development of this framework, you can do so by becoming asponsor. ❤️
This super simple example that displays a bunch of color schemes in a Carousel view.
It uses hex to set the color for the schemes. It leverages from.isDarkColor
to make the text color readable in all scenarios.
The demo also featuresSpots for rendering the Carousel view.
Example code:
letcolor=UIColor(hex:"#3b5998")backgroundColor= colorlabel.textColor= color.isDark?UIColor.whiteColor():UIColor.darkGrayColor()
This examples shows how much fun you can have with combiningCAGradientLayer
withCABasicAnimation
.
It uses.hex
for getting the colors and.gradient()
for transforminga collection ofUIColor
's into aCAGradientLayer
.
The demo featuresSpots for rendering the list view andFakery for generating random content strings.
Extract from the demo:
lazyvargradient:CAGradientLayer=[UIColor(hex:"#FD4340"),UIColor(hex:"#CE2BAE")].gradient{ gradientin gradient.speed=0 gradient.timeOffset=0return gradient}
Hue is available throughCocoaPods. To installit, simply add the following line to your Podfile:
pod'Hue'
Hue is also available throughCarthage.To install just write into your Cartfile:
github"hyperoslo/Hue"
To installHue usingSwift Package Manager with Xcode 11, just follow the instructions athttps://developer.apple.com/documentation/swift_packages and import the platform specific library to the project:
import Hue
Hyper made this with ❤️
We would love you to contribute toHue, check theCONTRIBUTING file for more info.
Credit goes out to Panic Inc who createdColorArt and@jathu for his work onUIImageColors which deeply inspired the functionality behind the image color analysis.
Hue is available under the MIT license. See the LICENSE file for more info.
About
🎨 Hue is the all-in-one coloring utility that you'll ever need.