Created
July 16, 2011 07:20
-
-
Save SquaredTiki/1086096 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
- (UIColor *)colorFromRGBValue:(NSString *)rgb { // General format is 'rgb(red, green, blue)' | |
if ([rgb rangeOfString:@"rgb"].location == NSNotFound) | |
return nil; | |
NSMutableString *mutableCopy = [rgb mutableCopy]; | |
[mutableCopy replaceCharactersInRange:NSMakeRange(0, 4) withString:@""]; | |
[mutableCopy replaceCharactersInRange:NSMakeRange(mutableCopy.length-1, 1) withString:@""]; | |
NSArray *components = [mutableCopy componentsSeparatedByString:@","]; | |
int red = [[components objectAtIndex:0] intValue]; | |
int green = [[components objectAtIndex:1] intValue]; | |
int blue = [[components objectAtIndex:2] intValue]; | |
UIColor *retVal = [UIColor colorWithRed:red/255.0 green:green/255.0 blue:blue/255.0 alpha:1.0]; | |
return retVal; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment