Skip to content

Instantly share code, notes, and snippets.

@SquaredTiki
Created July 16, 2011 07:20
Show Gist options
  • Save SquaredTiki/1086096 to your computer and use it in GitHub Desktop.
Save SquaredTiki/1086096 to your computer and use it in GitHub Desktop.
- (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