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

Overview

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.

Comments
  • Add umbrella header

    Add umbrella header

    When installing Hue with Carthage, you can run into issues when it cannot find the umbrella header. This PR aims to correct that issue.

    Should fix https://github.com/hyperoslo/Hue/issues/33

    opened by zenangst 10
  • Improve color(at:) function with dispatching and a completion closure

    Improve color(at:) function with dispatching and a completion closure

    Getting a color from an image happens in the main thread, this can cause slowdowns if the method is used frequently (e.g. a feed). To offload the main thread from extracting the pixel color of a specific point, the method will now use a completion closure that will be dispatched into the main thread when the color has been extracted. Internally color(at:) runs in a user interactive queue.

    opened by zenangst 5
  • Carthage problems when compiling with flag

    Carthage problems when compiling with flag "--platform iOS"

    Hello all,

    I'm getting the following error when trying to install Hue via Carthage:

    warning: no umbrella header found for target 'Hue-iOS', module map will not be generated

    The shell task exits with code 65. Any idea?

    Thank you

    opened by jorgej-ramos 5
  • Fix tests

    Fix tests

    • We changed signatures of some APIs, so the tests won't work. Fix it
    • Also, update pods and fix 2 demos
    • There is dominant color extractor test that fails. Maybe @vadymmarkov you can take a look at it?
    opened by onmyway133 3
  • SPM - Fix Xcode warning

    SPM - Fix Xcode warning

    Hue/Package.swift The iOS deployment target 'IPHONEOS_DEPLOYMENT_TARGET' is set to 8.0, but the range of supported deployment target versions is 9.0 to 15.0.99.

    opened by guidev 2
  • fixed Swift 4 warnings regarding use of `characters` property

    fixed Swift 4 warnings regarding use of `characters` property

    Hi,

    With Xcode 9 & Swift 4, you get some warnings because the use of the characters property is deprecated. This PR fixes these warnings.

    All tests passes.

    opened by frederik-jacques 2
  • Image colors white for all except background

    Image colors white for all except background

    I'm trying out image colors functionality and no matter which image I use it returns white color for primary, secondary and detail. Background color seems to work.

    opened by damirstuhec 2
  • Fix isDark and add test cases

    Fix isDark and add test cases

    This PR fixes #39

    Note: There is still a possibility for edge cases, where UIColor.specificColor.isDark is different from UIColor(hex: UIColor.specificColor.hex()).isDark, because of the floating point division. This is also noted in the test cases

    opened by ffittschen 2
  • Fix/hex init

    Fix/hex init

    This PR refactors the static .hex() method into init(hex:_).

    Why? Well, to me (and others 😎), it makes more sense for it to be an initializer than a static method returning a color based on the hex that you pass it.

    So instead of;

    let color = UIColor.hex("#ff0")
    

    You’ll do;

    let color = UIColor(hex:"#ff0")
    

    The old method is still there in this version but it is marked as deprecated.

    opened by zenangst 2
  • TableView's gradients cut off in landscape

    TableView's gradients cut off in landscape

    Hey I have a simple question. Have a split view controller that I am testing with Hue. Using your demo example, how do I modify it so that in landscape view the whole tableview has the gradients instead of partially cut off?

    opened by OptTrader 2
  • Support tvOS

    Support tvOS

    Added tvOS specification in Hue.podspec and a TV framework target for Carthage installation. It builds the same source files from iOS.

    Somehow xctool doesn't seem to work well with tvOS SDK so I use xcodebuild to run the tests for now.

    opened by bcylin 2
Releases(5.0.1)
Owner
Christoffer Winterkvist
random hero at @finkoslo by day, cocoa vigilante by night, dad at dawn. my life is awesome. Previously @hyperoslo
Christoffer Winterkvist
PrettyColors is a Swift library for styling and coloring text in the Terminal.

PrettyColors is a Swift library for styling and coloring text in the Terminal. The library outputs ANSI escape codes and conforms to ECMA Standard 48.

J.D. Healy 171 Aug 13, 2022
A pure Swift library for using ANSI codes. Basically makes command-line coloring and styling very easy!

Colors A pure Swift library for using ANSI codes. Basically makes command-line coloring and styling very easy! Note: Colors master requires Xcode 7.3

Chad Scira 27 Jun 3, 2021
All wikipedia colors implemented as easy to use UIColor extension 🌈

UIColor-WikiColors All wikipedia colors implemented as an easy to use UIColor extension. Have you ever tried using UIColor.lightBlue just to be welcom

Szymon Maślanka 58 Jul 30, 2022
Hue is the all-in-one coloring utility that you'll ever need

Hue is the all-in-one coloring utility that you'll ever need. Usage Hex You can easily use hex colors with the init(hex:) convenience initializer on U

Christoffer Winterkvist 3.4k Jan 3, 2023
The most perfect Swift Timer you'll ever need.

Timerable ⏰ The most perfect Swift Timer you'll ever need. A protocol-oriented Timer Factory with all the features you'll ever need. I wrote it in bot

Emad Beyrami 24 Dec 22, 2022
The only Connect API library you'd ever need

ConnectKit A Swift client for Infinite Flight's Connect APIs, built using the Network framework. Supported APIs IF Session Discovery Connect API V2 Op

Alexander Nikitin 7 Dec 14, 2022
A fast, convenient and nonintrusive conversion framework between JSON and model. Your model class doesn't need to extend any base class. You don't need to modify any model file.

MJExtension A fast, convenient and nonintrusive conversion framework between JSON and model. 转换速度快、使用简单方便的字典转模型框架 ?? ✍??Release Notes: more details Co

M了个J 8.5k Jan 3, 2023
TwilioChat_iOS - Twilio iOS SDK Implementaion Chat one-one Chat One-Many (Group)

TwilioChat_iOS - Twilio iOS SDK Implementaion Chat one-one Chat One-Many (Group) - Add Participant - Remove Participant Send Attachment Image Android - iOS Tested iOS - iOS Tested iOS - Android Tested React to Message, Delete a Message Read, Delivered, Sent Delete a Conversation Unread Messages Filter

Zeeshan Haider 2 May 23, 2022
PrettyColors is a Swift library for styling and coloring text in the Terminal.

PrettyColors is a Swift library for styling and coloring text in the Terminal. The library outputs ANSI escape codes and conforms to ECMA Standard 48.

J.D. Healy 171 Aug 13, 2022
A pure Swift library for using ANSI codes. Basically makes command-line coloring and styling very easy!

Colors A pure Swift library for using ANSI codes. Basically makes command-line coloring and styling very easy! Note: Colors master requires Xcode 7.3

Chad Scira 27 Jun 3, 2021
A pure Swift library for using ANSI codes. Basically makes command-line coloring and styling very easy!

Colors A pure Swift library for using ANSI codes. Basically makes command-line coloring and styling very easy! Note: Colors master requires Xcode 7.3

Chad Scira 27 Jun 3, 2021
Styling and coloring your XCTest logs on Xcode Console

XLTestLog Notes with Xcode 8 and XLTestLog Since Xcode 8 killed XcodeColors, the current way using XCTestLog on Xcode 8 is just plain texts with emoji

Xaree Lee 58 Feb 2, 2022
All the reusable code that we need in each project

SwiftyUtils SwiftyUtils groups all the reusable code that we need to ship in each project. This framework contains: Extensions Protocols Structs Subcl

Tom Baranes 529 Dec 25, 2022
Simple Swift class to provide all the configurations you need to create custom camera view in your app

Camera Manager This is a simple Swift class to provide all the configurations you need to create custom camera view in your app. It follows orientatio

Imaginary Cloud 1.3k Dec 29, 2022
All the reusable code that we need in each project

SwiftyUtils SwiftyUtils groups all the reusable code that we need to ship in each project. This framework contains: Extensions Protocols Structs Subcl

Tom Baranes 529 Dec 25, 2022
RxAlamoRecord combines the power of the AlamoRecord and RxSwift libraries to create a networking layer that makes interacting with API's easier than ever reactively.

Written in Swift 5 RxAlamoRecord combines the power of the AlamoRecord and RxSwift libraries to create a networking layer that makes interacting with

Dalton Hinterscher 9 Aug 7, 2020
May be the most elegant stepper you have ever had!

PFStepper It may be the most elegant stepper you have ever had! Usage To be written. Todo Documenting @IBDesignable supporting Animations Customizable

null 25 Dec 16, 2019
Have you ever wanted to just throw your optional like a table?

JebStolem Have you ever wanted to just throw your optional like a table? Or mayb

Piotr Szadkowski 1 Feb 23, 2022
Enable WebSocket in OPC DA/AE Server with JSON return, first time ever

WebSocket4OPC Enable WebSocket in OPC DA/AE Server with JSON return, first time ever DCOM was developed more than 2 decades ago, wich was the pillar o

null 13 Dec 14, 2022
Create fully customizable popups easier than ever before ⚜️

FlexFlex Create fully customizable popups easier than ever before. ?? Installation FlexFlex requires iOS 13 and Xcode 12. 1️⃣ In Xcode go to File ➤ Ad

adri567 2 Aug 15, 2022