---
title: "#195: Mastering UIColor with Hue 🌈"
url: https://littlebitesofcocoa.com/195-mastering-uicolor-with-hue
author: Jake Marsh
published: 2016-02-19
topics: ["Libraries","UIKit"]
description: "Today we'll check out a library from Hyper called Hue. It gives us all kinds of helpful utilities for working with colors, let's dive in."
---

# #195: Mastering UIColor with Hue 🌈

By Jake Marsh, February 19, 2016. HTML: https://littlebitesofcocoa.com/195-mastering-uicolor-with-hue

Today we'll check out a library from [Hyper](https://github.com/hyperoslo) called [Hue](https://github.com/hyperoslo/Hue). It gives us all kinds of helpful utilities for working with **colors**, let's dive in.

First, [Hue](https://github.com/hyperoslo/Hue) helps us easily can parse **colors** from hex **strings**:

``` swift
let beige = UIColor.hex("#FEFAF1")
let lightBrown = UIColor.hex("#AB9372")
let brown = UIColor.hex("#8C5637")
```

In addition, [Hue](https://github.com/hyperoslo/Hue) can analyze **colors**:

``` swift
beige.isDark // returns false
```

[Hue](https://github.com/hyperoslo/Hue) can easily create **gradients**. Here we'll take a couple of **colors**, and create a **CAGradientLayer** from them:

``` swift
let gradient = [lightBrown, brown].gradient { gradient in
  gradient.locations = [0.25, 1.0]
  return gradient
}
```

Finally, [Hue](https://github.com/hyperoslo/Hue) can analyze a **UIImage**, returning a **tuple** of **colors** it finds inside.

``` swift
let (bg, primary, secondary, _) = albumArt.colors()
```

It provides **background**, **primary**, **secondary** and **detail colors** from the **image**. We can the use these to create interfaces such as the one found in **iTunes** on **OS X**, where the colors in the UI match those found in the album artwork. Neat!

<img src='https://media.littlebitesofcocoa.com/bite-assets/195-mastering-uicolor-with-hue-example.png' style='max-width: 438px;' />

More info about _Hue_ can be found at [git.io/hue](http://git.io/hue)
