Slide 1

Slide 1 text

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

Slide 2

Slide 2 text

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)

Slide 3

Slide 3 text

O O P S … 
 self.view.backgroundColor = [UIColor colorWithRed:250.f/255.f 
 green: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.

Slide 4

Slide 4 text

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 
 green:0.678 
 blue:0.0 
 alpha:alpha]; }

Slide 5

Slide 5 text

There still remain the problem

Slide 6

Slide 6 text

I R E C O M M E N D Y O U T O …

Slide 7

Slide 7 text

B U I L D Y O U R O W N C O L O R PA L L E T S

Slide 8

Slide 8 text

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 >

Slide 9

Slide 9 text

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

Slide 10

Slide 10 text

NSColorList

Slide 11

Slide 11 text

– 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.”

Slide 12

Slide 12 text

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
 fromFile:self.inputURL.path];
 
 
 [colorList writeToFile:nil];
 


Slide 13

Slide 13 text

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

Slide 14

Slide 14 text

< 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

Slide 15

Slide 15 text

Thank you