Need help with HexColors?
Click the “chat” button below for chat support from the developer who created it, or find similar developers for support.

About the developer

459 Stars 98 Forks MIT License 156 Commits 3 Opened issues


HexColors is an extension for UIColor and NSColor to support for creating colors from a hex strings

Services available


Need anything else?

Contributors list


Platform Xcode Swift Downloads Month Cocoapods Build Status codecov

HexColors is an extension for UIColor and NSColor to support for creating colors from a hex string like #FF0088 or 8844FF and back to a String. Completely rewritten in Swift 3!

If you want to use this in Objective-C jump to the 4.X version tag. If you want to use this in Swift < 3.2 use the 5.X version tag.


Swift 4.0 compatiblity


How to use HexColors in the different systems.

iOS / watchOS / tvOS

Generating UIColors

let colorWithHex = UIColor("#ff8942")
let colorWithoutHex = UIColor("ff8942")
let colorWithHexAndAlhpa = UIColor("#ff8942DF")
let colorWithoutHexAndAlhpa = UIColor("ff8942DF")
let shortColorWithHex = UIColor("#fff")
let shortColorWithoutHex = UIColor("fff")
let shortColorWithHexAndAlpha = UIColor("#FFFD")
let shortColorWithoutHexAndAlpha = UIColor("#FFFD")

Generating Hex Strings from UIColor

let colorWithHex = UIColor("#ff8942")
let stringFromColor = colorWithHex.hex


Generating NSColor

let colorWithHex = NSColor("#ff8942")
let colorWithoutHex = NSColor("ff8942")
let colorWithHexAndAlhpa = NSColor("#ff8942DF")
let colorWithoutHexAndAlhpa = NSColor("ff8942DF")
let shortColorWithHex = NSColor("#fff")
let shortColorWithoutHex = NSColor("fff")
let shortColorWithHexAndAlpha = NSColor("#FFFD")
let shortColorWithoutHexAndAlpha = NSColor("#FFFD")

Generating Hex Strings from NSColor

let colorWithHex = NSColor("#ff8942")
let stringFromColor = colorWithHex.hex



HexColors requires >= iOS 8.0 and >=macOS 10.9.


Add HexColors to your Podfile:

pod 'HexColors'
pod install HexColors


Add HexColors to your Cartfile:

github "mRs-/HexColors"

Swift Package Manager

To work with the Swift Package Manager you need to add a Package.swift file and defining your package.

import PackageDescription

let package = Package( name: "YourPackageName", dependencies: [ .Package(url: "", majorVersion: 5), ] )

Then execute the Swift Package Manager with the following Shell commands:

swift build


Simply just drag and drop the HexColors.swift in your project.


HexColors was created by Marius Landwehr because of the pain to create Colors from a API (mostly hex) converting to a UI/NSColor.


Marius Landwehr @mariusLAN


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

We use cookies. If you continue to browse the site, you agree to the use of cookies. For more information on our use of cookies please see our Privacy Policy.