Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Category for NSColor allowing one to easily set / get a color using hexadecimal notation

branch: master

Fetching latest commit…

Octocat-spinner-32-eaf2f5

Cannot retrieve the latest commit at this time

Octocat-spinner-32 CINSColor+Hex.app
Octocat-spinner-32 CINSColor+Hex.xcodeproj
Octocat-spinner-32 CINSColor+Hex
Octocat-spinner-32 .gitignore
Octocat-spinner-32 README.md
Octocat-spinner-32 faceleg_icon.icns
README.md

Why?

I finally realised that [UtilFunctions colorToHex:color] isn't as elegant as a category on NSColor.

Usage

Using a hexadecimal color to create an NSColor:

@try {
    // Both shorthand and full forms of hexadecimal colours are accepted
    [colorWell setColor:[NSColor colorWithHex:@"#F00"]];
    [colorWell setColor:[NSColor colorWithHex:@"#Ff0000"]];
}
@catch (NSException *exception) {
    NSLog(@"%@", [exception description]);
}

It'll throw an exception if one attempts to use a string that is not 3 or 6 characters in length, excluding the hash.


Getting the hexadecimal representation of a given NSColor:

NSString *hexColor = [color hexColor]

More Information

See this blog post: Extracting hex value from NSColor. Get this & more useful Cocoa Categories here: Cocoa Categories;

Something went wrong with that request. Please try again.