Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Build Your Own Color Pallet

Build Your Own Color Pallet



Yusei Nishiyama

October 22, 2014


  1. B U I L D Y O U R O

    W N C O L O R PA L L E T S Yu s e i N i s h i y a m a ( C o o k p a d i n c . ) O c t o b e r 2 2 , 2 0 1 4 @ p o t a t o t i p s # 1 0
  2. W H O A M I ? • Mobile app

    engineer • Develop apps for iOS • Regulate “Auto Layout” day after day… :’-( • I’m interested in • Metal (new graphics API of Apple) • Functional programming (with Swift) • Reactive programming (Reactive Cocoa) Twitter: @yuseinishiyama
 GitHub: https://github.com/yuseinishiyama
 Blog: yuseinishiyama.com
 (not so active)
  3. O O P S … 
 self.view.backgroundColor = [UIColor colorWithRed:250.f/255.f

 blue:245.f/255.f alpha:1.f]; 
 _someLabel.textColor = [UIColor colorWithRed:181.f/255.f green:177.f/255.f blue:169.f/255.f alpha:1.f];
 It’s so hard to maintain.
  4. W E N E E D M O R E

    U N I F I E D WAY @implementation UIColor (CookpadUIColors) ! + (UIColor *)cui_greenColor { return [self cui_greenColorWithAlpha:1.0]; } ! + (UIColor *)cui_greenColorWithAlpha:
 (CGFloat)alpha { return [self colorWithRed:0.545 
 alpha:alpha]; }
  5. There still remain the problem

  6. I R E C O M M E N D

    Y O U T O …
  7. B U I L D Y O U R O

    W N C O L O R PA L L E T S
  8. Y O U C A N F I N D

    I T AT 
 < ~ / L i b r a r y / C o l o r s / * . c l r >
  9. I S T H I S F I N I

    S H E D ? • Once created, you can’t modify it • GUI Only • There is no way to automate
  10. NSColorList

  11. – M A C D E V E L O

    P E R L I B R A RY “An NSColorList object is an ordered list of NSColor objects, …The NSColorPanel list mode color picker uses instances of NSColorList to represent any lists of colors that come with the system, as well as any lists created by the user. An application can use NSColorList to manage document-specific color lists.”
  12. R E A D A N D W R I

    T E • Read from a file 
 • Install a color list 
 NSColorList *colorList = 
 [[NSColorList alloc] initWithName:colorListName
 [colorList writeToFile:nil];

  13. NSURL *inputURL = 
 [NSURL fileURLWithPath:@“~/Library/Colors/potatotips.clr"]; 
 NSString *colorListName =

 [[inputURL lastPathComponent] stringByDeletingPathExtension]; 
 NSColorList *colorList = 
 [[NSColorList alloc] initWithName:colorListName 
 fromFile:self.inputURL.path]; ! NSColor *hogeColor = 
 [NSColor colorWithRed:0.5 green:0.5 blue:0.5 alpha:1];
 ! [colorList insertColor:hogeColor key:@"HogeColor" atIndex:0]; 
 [colorList writeToFile:nil]; E D I TA B L E
  14. < s q u a re / o b j

    c - c o d e g e n u t i l s > • Generate codes from .crl files • https://github.com/square/objc-codegenutils/tree/ master/colordump • brew install objc-codegenutils
  15. Thank you