Last active
July 11, 2017 09:52
-
-
Save itsthejb/9251618 to your computer and use it in GitHub Desktop.
UIColor category for http://flatuicolors.com/
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
import UIKit | |
public extension UIColor { | |
public struct Flat { | |
public static var turquoise: UIColor { | |
return UIColor(red: 026.0/255, green: 188.0/255, blue: 156.0/255, alpha: 1.0) | |
} | |
public static var emerald: UIColor { | |
return UIColor(red: 046.0/255, green: 204.0/255, blue: 113.0/255, alpha: 1.0) | |
} | |
public static var peterRiver: UIColor { | |
return UIColor(red: 052.0/255, green: 152.0/255, blue: 219.0/255, alpha: 1.0) | |
} | |
public static var amethyst: UIColor { | |
return UIColor(red: 155.0/255, green: 089.0/255, blue: 182.0/255, alpha: 1.0) | |
} | |
public static var wetAsphalt: UIColor { | |
return UIColor(red: 052.0/255, green: 073.0/255, blue: 094.0/255, alpha: 1.0) | |
} | |
public static var greenSea: UIColor { | |
return UIColor(red: 022.0/255, green: 160.0/255, blue: 133.0/255, alpha: 1.0) | |
} | |
public static var nephritis: UIColor { | |
return UIColor(red: 039.0/255, green: 174.0/255, blue: 096.0/255, alpha: 1.0) | |
} | |
public static var belizeHole: UIColor { | |
return UIColor(red: 041.0/255, green: 128.0/255, blue: 185.0/255, alpha: 1.0) | |
} | |
public static var wisteria: UIColor { | |
return UIColor(red: 142.0/255, green: 068.0/255, blue: 173.0/255, alpha: 1.0) | |
} | |
public static var midnightBlue: UIColor { | |
return UIColor(red: 044.0/255, green: 062.0/255, blue: 080.0/255, alpha: 1.0) | |
} | |
public static var sunFlower: UIColor { | |
return UIColor(red: 241.0/255, green: 196.0/255, blue: 015.0/255, alpha: 1.0) | |
} | |
public static var carrot: UIColor { | |
return UIColor(red: 230.0/255, green: 126.0/255, blue: 034.0/255, alpha: 1.0) | |
} | |
public static var alizarin: UIColor { | |
return UIColor(red: 231.0/255, green: 076.0/255, blue: 060.0/255, alpha: 1.0) | |
} | |
public static var clouds: UIColor { | |
return UIColor(red: 236.0/255, green: 240.0/255, blue: 241.0/255, alpha: 1.0) | |
} | |
public static var concrete: UIColor { | |
return UIColor(red: 149.0/255, green: 165.0/255, blue: 166.0/255, alpha: 1.0) | |
} | |
public static var orange: UIColor { | |
return UIColor(red: 243.0/255, green: 156.0/255, blue: 018.0/255, alpha: 1.0) | |
} | |
public static var pumpkin: UIColor { | |
return UIColor(red: 211.0/255, green: 084.0/255, blue: 000.0/255, alpha: 1.0) | |
} | |
public static var pomegranate: UIColor { | |
return UIColor(red: 192.0/255, green: 057.0/255, blue: 043.0/255, alpha: 1.0) | |
} | |
public static var silver: UIColor { | |
return UIColor(red: 189.0/255, green: 195.0/255, blue: 199.0/255, alpha: 1.0) | |
} | |
public static var asbestos: UIColor { | |
return UIColor(red: 127.0/255, green: 140.0/255, blue: 141.0/255, alpha: 1.0) | |
} | |
public static var all: [UIColor] { | |
return [turquoise, emerald, peterRiver, amethyst, wetAsphalt, greenSea, | |
nephritis, belizeHole, wisteria, midnightBlue, sunFlower, carrot, | |
alizarin, clouds, concrete, orange, pumpkin, pomegranate, silver, asbestos] | |
} | |
public static var random: UIColor { | |
return all[Int(arc4random_uniform(UInt32(all.count)))] | |
} | |
} | |
} |
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+FlatUIColors.h | |
// Colors | |
// | |
// Created by Jonathan Crooke on 27/02/2014. | |
// | |
// Colours courtesty of http://flatuicolors.com/ | |
#import <UIKit/UIKit.h> | |
@interface UIColor (FlatUIColors) | |
+ (instancetype) flat_turquoise; | |
+ (instancetype) flat_emerald; | |
+ (instancetype) flat_peterRiver; | |
+ (instancetype) flat_amethyst; | |
+ (instancetype) flat_wetAsphalt; | |
+ (instancetype) flat_greenSea; | |
+ (instancetype) flat_nephritis; | |
+ (instancetype) flat_belizeHole; | |
+ (instancetype) flat_wisteria; | |
+ (instancetype) flat_midnightBlue; | |
+ (instancetype) flat_sunFlower; | |
+ (instancetype) flat_carrot; | |
+ (instancetype) flat_alizarin; | |
+ (instancetype) flat_clouds; | |
+ (instancetype) flat_concrete; | |
+ (instancetype) flat_orange; | |
+ (instancetype) flat_pumpkin; | |
+ (instancetype) flat_pomegranate; | |
+ (instancetype) flat_silver; | |
+ (instancetype) flat_asbestos; | |
+ (instancetype) flat_random; | |
+ (NSUInteger) flat_numberOfColors; | |
+ (instancetype) flat_colorAtIndex:(NSUInteger) index; | |
@end |
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+FlatUIColors.m | |
// Colors | |
// | |
// Created by Jonathan Crooke on 27/02/2014. | |
// | |
#import "UIColor+FlatUIColors.h" | |
@interface UIColor (FlatUIColorsPrivate) | |
+ (instancetype) flat_colorWithString:(NSString*) string; | |
+ (NSArray*) flat_colorSelectorArray; | |
@end | |
@implementation UIColor (FlatUIColors) | |
+ (instancetype)flat_colorWithString:(NSString *)string { | |
static NSCache *cache = nil; | |
static dispatch_once_t onceToken; | |
dispatch_once(&onceToken, ^{ | |
cache = [[NSCache alloc] init]; | |
}); | |
UIColor *cachedColour = [cache objectForKey:string]; | |
if (!cachedColour) { | |
NSArray *components = [string componentsSeparatedByString:@","]; | |
cachedColour = [UIColor colorWithRed:[components[0] floatValue] / 255 | |
green:[components[1] floatValue] / 255 | |
blue:[components[2] floatValue] / 255 | |
alpha:1.0]; | |
[cache setObject:cachedColour forKey:string]; | |
} | |
return cachedColour; | |
} | |
+ (NSArray *)flat_colorSelectorArray { | |
static NSArray *selectors = nil; | |
static dispatch_once_t onceToken; | |
dispatch_once(&onceToken, ^{ | |
selectors = @[ | |
@"flat_turquoise", | |
@"flat_emerald", | |
@"flat_peterRiver", | |
@"flat_amethyst", | |
@"flat_wetAsphalt", | |
@"flat_greenSea", | |
@"flat_nephritis", | |
@"flat_belizeHole", | |
@"flat_wisteria", | |
@"flat_midnightBlue", | |
@"flat_sunFlower", | |
@"flat_carrot", | |
@"flat_alizarin", | |
@"flat_clouds", | |
@"flat_concrete", | |
@"flat_orange", | |
@"flat_pumpkin", | |
@"flat_pomegranate", | |
@"flat_silver", | |
@"flat_asbestos", | |
]; | |
}); | |
return selectors; | |
} | |
+ (NSUInteger)flat_numberOfColors { | |
return [self flat_colorSelectorArray].count; | |
} | |
+ (instancetype)flat_colorAtIndex:(NSUInteger)index { | |
NSParameterAssert(index < [self flat_numberOfColors]); | |
NSArray *selectors = [self flat_colorSelectorArray]; | |
NSString *selectorString = selectors[index]; | |
#pragma clang diagnostic push | |
#pragma clang diagnostic ignored "-Warc-performSelector-leaks" | |
return [UIColor performSelector:NSSelectorFromString(selectorString)]; | |
#pragma clang diagnostic pop | |
} | |
+ (instancetype)flat_random { | |
return [self flat_colorAtIndex:arc4random() % [self flat_numberOfColors]]; | |
} | |
+ (instancetype) flat_turquoise { return [self flat_colorWithString:@"026, 188, 156"]; } | |
+ (instancetype) flat_emerald { return [self flat_colorWithString:@"046, 204, 113"]; } | |
+ (instancetype) flat_peterRiver { return [self flat_colorWithString:@"052, 152, 219"]; } | |
+ (instancetype) flat_amethyst { return [self flat_colorWithString:@"155, 089, 182"]; } | |
+ (instancetype) flat_wetAsphalt { return [self flat_colorWithString:@"052, 073, 094"]; } | |
+ (instancetype) flat_greenSea { return [self flat_colorWithString:@"022, 160, 133"]; } | |
+ (instancetype) flat_nephritis { return [self flat_colorWithString:@"039, 174, 096"]; } | |
+ (instancetype) flat_belizeHole { return [self flat_colorWithString:@"041, 128, 185"]; } | |
+ (instancetype) flat_wisteria { return [self flat_colorWithString:@"142, 068, 173"]; } | |
+ (instancetype) flat_midnightBlue { return [self flat_colorWithString:@"044, 062, 080"]; } | |
+ (instancetype) flat_sunFlower { return [self flat_colorWithString:@"241, 196, 015"]; } | |
+ (instancetype) flat_carrot { return [self flat_colorWithString:@"230, 126, 034"]; } | |
+ (instancetype) flat_alizarin { return [self flat_colorWithString:@"231, 076, 060"]; } | |
+ (instancetype) flat_clouds { return [self flat_colorWithString:@"236, 240, 241"]; } | |
+ (instancetype) flat_concrete { return [self flat_colorWithString:@"149, 165, 166"]; } | |
+ (instancetype) flat_orange { return [self flat_colorWithString:@"243, 156, 018"]; } | |
+ (instancetype) flat_pumpkin { return [self flat_colorWithString:@"211, 084, 000"]; } | |
+ (instancetype) flat_pomegranate { return [self flat_colorWithString:@"192, 057, 043"]; } | |
+ (instancetype) flat_silver { return [self flat_colorWithString:@"189, 195, 199"]; } | |
+ (instancetype) flat_asbestos { return [self flat_colorWithString:@"127, 140, 141"]; } | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment