Created
September 19, 2013 00:39
-
-
Save nicwise/6617756 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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