Git Product home page Git Product logo

nsstring-color's Introduction

#NSString+Color Build Status

Category on NSString allowing simple color instantiation from its content. Support web colors also.

##Description This category adds four methods to NSString.

  • (UIColor *)colorFromRGBcode // Consider string as an hexadecimal RGB code
  • (UIColor *)colorFromRGBAcode // Consider string as an hexadecimal RGBA code
  • (UIColor *)colorFromName // Consider string as a webcolor name, UIColor selector name
  • (UIColor *)representedColor // This method will automatically choose between three others methods in order to generate a color

This allows you to load color codes from configuration file, such as PLIST and create colors to configure your views background color for example. All created colors are cached using NSCache, allowing you to reuse them. Webcolor names are case insensitive, and you can specify UIColor selectors name without Color suffix.

For a list of webcolors, http://en.wikipedia.org/wiki/Web_colors

ScreenShot

##Usage

  • simply call one of added method on an NSString object
  • Preferred way is using representedColor method which will detect right color format

##Example

  [@"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

##Advantages

  • Allows you to load colors from configuration files
  • Remove all boilerplate code induced by format checking
  • Add web colors

##Bonus If you are using UIColor categories to add some color code to your project, such as https://github.com/magtory/FPBrandColors, you can load them from configuration file too.

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

##Consideration While colorFromName will return nil if color name is unknown, colorFromRGBAcode and colorFromRGBcode will return you an undefined color if hexadecimal code is invalid. Same apply to representedColor when forcing hexadecimal format (Prefixing with #)

##Installation Cocoapods: pod 'NSString+Colors'
Manual: Copy the Classes folder in your project

Import header in your project. .pch is a good place ;)

#import "NSString+Colors.h"

##Versions 1.0 : Initial release

nsstring-color's People

Contributors

nicolasgoutaland avatar

Watchers

James Cloos avatar Massimo avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.