Skip to content

Instantly share code, notes, and snippets.

@sonburn
Created March 30, 2018 21:29
Show Gist options
  • Select an option

  • Save sonburn/50964351128cab3e5d2703d6edcb9f19 to your computer and use it in GitHub Desktop.

Select an option

Save sonburn/50964351128cab3e5d2703d6edcb9f19 to your computer and use it in GitHub Desktop.
function hexToColor(hex,alpha) {
var result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex),
r = parseInt(result[1],16) / 255,
g = parseInt(result[2],16) / 255,
b = parseInt(result[3],16) / 255,
a = (typeof alpha !== 'undefined') ? alpha : 1;
return NSColor.colorWithCalibratedRed_green_blue_alpha(r,g,b,a);
}
var color = hexToColor('000000');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment