UIColor Extension for Getting a Lighter / Darker Shade of a Given Colour

Ross Butler
1 min readApr 20, 2017

--

Added a UIColor extension to the Swift extensions repository I maintain on GitHub which allows a developer to quickly obtain a lighter or darker shade of an existing colour. The idea came from a pull request I recently made to another open source repository whereby I wanted the developer to be a set a colour for some video controls and have the playback remaining on the video scrubbing bar automatically take on a darker shade so that the difference between playback elapsed and playback remaining was clearly indicated. Additionally, the darker shade of the selected colour would be used as the tint colour for the highlighted state.

The extension allows the developer to obtain a dark shade of blue as follows:

let darkBlue = UIColor.blue.shade(.darker)

A lighter shade can be obtained in similar fashion:

let lightBlue = UIColor.blue.shade(.lighter)

Varying shades of lightness and darkness are available but should the developer not be able to find a suitable shade then the scaling factor used to obtain the new shade may be specified:

let veryDark = 0.1

let darkerBlue = UIColor.blue.shade(.darkness(veryDark))

The extension on UIColor can be found here: https://github.com/rwbutler/TailorSwift/blob/master/TailorSwift/Classes/UIColorAdditions.swift

--

--

Ross Butler

Senior Engineering Manager @ Go City. All views are my own.