Skip to content

Instantly share code, notes, and snippets.

@nicwise
Created September 19, 2013 00:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nicwise/6617756 to your computer and use it in GitHub Desktop.
Save nicwise/6617756 to your computer and use it in GitHub Desktop.
public static UIColor ToUIColor(this string hexString)
{
if (hexString.Contains("#")) hexString = hexString.Replace("#", "");
if (hexString.Length != 6) return UIColor.Red;
int red = Int32.Parse(hexString.Substring(0,2), System.Globalization.NumberStyles.AllowHexSpecifier);
int green = Int32.Parse(hexString.Substring(2,2), System.Globalization.NumberStyles.AllowHexSpecifier);
int blue = Int32.Parse(hexString.Substring(4,2), System.Globalization.NumberStyles.AllowHexSpecifier);
return UIColor.FromRGB(red, green, blue);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment