Get Updates By E-mail 

Article Written By:
Johann Dowa

An NSString Category For Easily Getting UIColor Selectors By Name Or Value

  •  
  •  
  •  
  •  
  •  

Earlier this year I mentioned a UIColor category providing easy access to specific colors using brand names and late last year a uicolor category providing easy access to iOS 7 colors.

Here’s a NSSTring category submitted by Nicolas Goutaland that makes it easier to utilize the aformentioned color libraries adding methods for gathering UIColor selectors using the rgb or rgba values, or name, to NSString. This makes it very easy to load colors from a PLIST file.

Here’s an example from the readme showing different methods, and ways you can represent colors with NSString+Color:

[@"red" representedColor];        // UIColor selector name without suffix
[@"redColor" representedColor];   // UIColor full selector name
[@"#FFEE55" representedColor];    // RGB Hexadecimal code. Prefix with # to force hexadecimal method
[@"FFEE55" representedColor];     // RGB Hexadecimal code. Will also work, but will be checked through a regex first
[@"#eeEEEe77" representedColor];  // RGB and RGBA Hexadecimal code are case insensitive too
[@"roSyBroWn" representedColor];  // Web color case insensitive

[@"FFEE55" colorFromRGBcode];     // Hexadecimal code
[@"red" colorFromName];           // UIColor selector name, without color suffix
[@"redColor" colorFromName];      // UIColor full selector name
[@"red" colorFromName];           // UIColor selector name, without color suffix
[@"roSyBroWn" colorFromName];     // Web color case insensitive

And to work with colors from other UIColor categories such as FPBrandColors you can simply use something like:

[@"Facebook" representedColor];        // UIColor selector name from FPBrandColors
[@"Github" representedColor];          // UIColor selector name from FPBrandColors

You can find NSString-Color on Github here.

A nice add-on for easily getting the right color.


  •  
  •  
  •  
  •  
  •  

Submit A Resource

Have you created a useful tutorial, library or tool for iOS development that you would like to get in front of our 300,000+ monthly page views from iOS developers?

You can submit the url here.

The resources we feel will appeal to our readers the most will be posted on the front page.

Comments