• Stars
    star
    3,463
  • Rank 12,304 (Top 0.3 %)
  • Language
    Swift
  • License
    Other
  • Created over 8 years ago
  • Updated 8 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

🎨 Hue is the all-in-one coloring utility that you'll ever need.

Hue

Hue is the all-in-one coloring utility that you'll ever need.

Version Carthage Compatible License Platform Swift

Usage

Hex

Hue IconYou can easily use hex colors with the init(hex:) convenience initializer on UIColor. It supports the following hex formats #ffffff, ffffff, #fff, fff

let white = UIColor(hex: "#ffffff")
let black = UIColor(hex: "#000000")
let red = UIColor(hex: "#ff0000")
let blue = UIColor(hex: "#0000ff")
let green = UIColor(hex: "#00ff00")
let yellow = UIColor(hex: "#ffff00")

Computed color properties

let white = UIColor(hex: "#ffffff")
let black = UIColor(hex: "#000000")

if white.isDarkColor {} // return false
if white.isBlackOrWhite {} // return true

Alpha

.alpha is a sugar for colorWithAlphaComponent, internally it does the exact same thing, think of it as a lipstick for your implementation.

let colorWithAlpha = myColor.alpha(0.75)

Gradients

You can easily create gradient layers using the gradient() method on arrays with UIColor. As an extra bonus, you can also add a transform closure if you want to modify the CAGradientLayer.

let gradient = [UIColor.blackColor(), UIColor.orangeColor()].gradient()

let secondGradient = [UIColor.blackColor(), UIColor.orangeColor()].gradient { gradient in
  gradient.locations = [0.25, 1.0]
  return gradient
}

Image colors

let image = UIImage(named: "My Image")
let (background, primary, secondary, detail) = image.colors()

Components

You can get red, green, blue, and alpha components from any UIColor by using the (red|green|blue|alpha)Component property.

let myColor = UIColor(hex: "#ffafc2")
let myColorBlueComponent = myColor.blueComponent
let myColorGreenComponent = myColor.greenComponent
let myColorRedComponent = myColor.redComponent
let myColorAlphaComponent = myColor.alphaComponent

Blending

let red = UIColor.redColor()
let green = UIColor.greenColor()
let yellow = red.addRGB(green)

let desaturatedBlue = UIColor(hex: "#aaaacc")
let saturatedBlue = desaturatedBlue.addHue(0.0, saturation: 1.0, brightness: 0.0, alpha: 0.0)

Supporting the project

If you want to support the development of this framework, you can do so by becoming a sponsor. ❀️

Examples

Hex Example screenshot

Hex

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 features Spots for rendering the Carousel view.

Example code:

let color = UIColor(hex: "#3b5998")
backgroundColor = color
label.textColor = color.isDark
  ? UIColor.whiteColor()
  : UIColor.darkGrayColor()

Gradients

Gradients Example screenshot

This examples shows how much fun you can have with combining CAGradientLayer with CABasicAnimation.

It uses .hex for getting the colors and .gradient() for transforming a collection of UIColor's into a CAGradientLayer.

The demo features Spots for rendering the list view and Fakery for generating random content strings.

Extract from the demo:

lazy var gradient: CAGradientLayer = [
  UIColor(hex: "#FD4340"),
  UIColor(hex: "#CE2BAE")
  ].gradient { gradient in
    gradient.speed = 0
    gradient.timeOffset = 0

    return gradient
  }

Installation

Hue is available through CocoaPods. To install it, simply add the following line to your Podfile:

pod 'Hue'

Hue is also available through Carthage. To install just write into your Cartfile:

github "hyperoslo/Hue"

To install Hue using Swift Package Manager with Xcode 11, just follow the instructions at https://developer.apple.com/documentation/swift_packages and import the platform specific library to the project:

import Hue

Author

Hyper made this with ❀️

Contribute

We would love you to contribute to Hue, check the CONTRIBUTING file for more info.

Credits

Credit goes out to Panic Inc who created ColorArt and @jathu for his work on UIImageColors which deeply inspired the functionality behind the image color analysis.

License

Hue is available under the MIT license. See the LICENSE file for more info.

More Repositories

1

Spots

🎍 Spots is a cross-platform view controller framework for building component-based UIs
Swift
1,313
star
2

Gray

πŸŒ“ Tailor your macOS Mojave experience
Swift
1,276
star
3

Blueprints

πŸŒ€ Blueprints - A framework that is meant to make your life easier when working with collection view flow layouts.
Swift
991
star
4

KeyboardCowboy

⌨️ The missing keyboard shortcut utility for macOS
Swift
535
star
5

Syncalicious

🍫 Syncalicious
Swift
356
star
6

Vaccine

πŸ’‰ Vaccine - Make your apps immune to recompile-disease
Swift
303
star
7

Family

🚸 A child view controller framework that makes setting up your parent controllers as easy as pie.
Swift
250
star
8

Tailor

πŸ‘”A super fast & convenient object mapper tailored for your needs
Swift
243
star
9

Versions

❇️Helping you find inner peace when comparing version numbers in Swift.
Swift
207
star
10

MarvinXcode

πŸ”¨A collection of nifty commands for your everyday workflow in Xcode
Swift
125
star
11

Differific

β›½ Differific - a fast and convenient diffing framework.
Swift
124
star
12

Coda-2-Modes

Modes for Coda 2
AppleScript
61
star
13

UserInterface

πŸš₯ UserInterface - a collection of convenience extensions specifically tailored to building user interfaces in Swift.
Swift
51
star
14

ToTheTop

πŸ”To the top - A small macOS application to help you scroll to the top.
Swift
36
star
15

Zcode

Work around Apples restriction with running Xcode 6.4 on El Capitan Developer Preview 2
Swift
25
star
16

NSString-ZENInflections

Returns camelCased, UpperCamelCased, dashed-case, snake_cased representations of an NSString
Objective-C
25
star
17

Inflection

The Optimus Prime of string inflection
Swift
22
star
18

MouseDef

🐭Move and resize windows by holding down modifier keys
Swift
21
star
19

ChangeMarks

Change Marks helps you to keep track of your most recent changes by giving them a different background color.
Objective-C
14
star
20

OSX-Configuration

My personal OS X configurations
Shell
10
star
21

ZenCode

πŸ”¨ZenCode for Xcode - A collection of nifty commands for your everyday workflow in Xcode.
Swift
9
star
22

Voodoo

πŸ’€ Voodoo is a set of Sourcery templates to make you do more with less.
Swift
7
star
23

Apps

Swift
7
star
24

Houston

Swift
6
star
25

WindowFlex

Helps you flex your Xcode window muscles
Objective-C
6
star
26

Storage

Swift
5
star
27

AXEssibility

Swift
5
star
28

Mapper

An object mapper for Swift
Swift
4
star
29

Marvin-Xcode-Extension

πŸ”¨A collection of nifty commands for your everyday workflow in Xcode 8
Swift
4
star
30

Xcode-Templates

πŸ”¨ Xcode templates
Swift
4
star
31

DirectoryObserver

Observing the file-system, easy as 1 2 3!
Swift
3
star
32

Goldfish

Something something secret ... goldfish.
Swift
3
star
33

TextMate-1-Bundle

Commands and Snippets I use everyday at work
3
star
34

coda-command-line

Coda 2 command line tool
Objective-C
3
star
35

XcodeConfiguration

3
star
36

C.mode

C mode for Coda 2
AppleScript
3
star
37

GoldenRetriever

Swift
2
star
38

dotfiles

My dotfiles
Vim Script
2
star
39

xcode-fish

Find and open xcworkspace or xcproject in Xcode.
Shell
2
star
40

LaunchArguments

Swift
2
star
41

xcode-espresso-tribute-theme

A light theme inspired by the Espresso - The Web Editor
2
star
42

xcode-ios-project

Ruby
2
star
43

MachPort

Swift
2
star
44

ZENFramework

Just another PHP MVC framework
PHP
2
star
45

HideDockAndStageManager

Swift
2
star
46

Windows

Swift
2
star
47

NSString-ZENVersions

Helping you find inner peace when comparing version numbers.
Objective-C
2
star
48

ApacheConf.mode

Apache configuration mode for Coda 2
1
star
49

theme-oh-my-sushi

oh-my-sushi
Shell
1
star
50

SidebarFlex

Objective-C
1
star
51

Retina

Swift
1
star
52

KeyCodes

Swift
1
star
53

StageManagerAppWindowGroupingBehavior

Swift
1
star
54

Swift.mode

1
star
55

DockManager

Swift
1
star
56

xc

Swift
1
star
57

haml.mode

HAML mode for Coda 2
1
star
58

ERB.mode

Ruby ERB mode for Coda 2
AppleScript
1
star
59

Ruby.mode

Ruby mode for Coda 2
AppleScript
1
star
60

emolator

TBD
1
star
61

DefaultKeyBinding

Custom keyboard shortcuts for OS X
1
star