Skip to content

Commit

Permalink
Added support for UIColor
Browse files Browse the repository at this point in the history
  • Loading branch information
oscardelben committed Sep 13, 2011
2 parents 6e138a9 + ba33f96 commit 0ddbd84
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 3 deletions.
3 changes: 3 additions & 0 deletions ColorPicker/AppController.m
Expand Up @@ -170,6 +170,9 @@ - (void)copyColorToPasteboard:(NSColor *)color
[pasteBoard setString:[color colorToCMYKRepresentation] forType:NSStringPboardType];
break;
case kFormatRGB:
case kFormatUIColor:
[pasteBoard setString:[color colorToUIColorRepresentation] forType:NSStringPboardType];
break;
default:
[pasteBoard setString:[color colorToRGBRepresentation] forType:NSStringPboardType];
break;
Expand Down
3 changes: 2 additions & 1 deletion ColorPicker/Constants.h
Expand Up @@ -13,7 +13,8 @@ typedef enum {
kFormatHEX,
kFormatHexWithoutHash,
kFormatRGB,
kFormatCMYK
kFormatCMYK,
kFormatUIColor
} kFormats;

#define kNumberOfColorsHistory 5
Expand Down
5 changes: 4 additions & 1 deletion ColorPicker/NSColorFormatter.h
Expand Up @@ -16,9 +16,12 @@
/* returns #ff0000 */
- (NSString*)colorToHEXRepresentation;

/* returns #ff0000 */
/* returns ff0000 */
- (NSString*)colorToHEXWithoutHashRepresentation;

/* returns [UIColor colorWithRed:1.0 green:1.0 blue:1.0 alpha:1.0] */
- (NSString*)colorToUIColorRepresentation;

/* returns 30° */
- (NSString*)colorToHueRepresentation;

Expand Down
11 changes: 11 additions & 0 deletions ColorPicker/NSColorFormatter.m
Expand Up @@ -82,6 +82,17 @@ - (NSString*)colorToHEXWithoutHashRepresentation
return hex;
}


- (NSString*)colorToUIColorRepresentation
{
NSString *uiColor = [NSString stringWithFormat:@"[UIColor colorWithRed:%.2f green:%.2f blue:%.2f alpha:1.0];",
[self redComponent],
[self greenComponent],
[self blueComponent]];

return uiColor;
}

- (NSString*)colorToHueRepresentation
{
float h = [self hueComponent];
Expand Down
19 changes: 18 additions & 1 deletion ColorPicker/PreferencesController.xib
Expand Up @@ -324,6 +324,16 @@
<string key="NSAction">_popUpItemAction:</string>
<reference key="NSTarget" ref="186846319"/>
</object>
<object class="NSMenuItem" id="36233711">
<reference key="NSMenu" ref="494084656"/>
<string key="NSTitle">UIColor ([UIColor colorWithRed:1.0...)</string>
<string key="NSKeyEquiv"/>
<int key="NSMnemonicLoc">2147483647</int>
<reference key="NSOnImage" ref="857830830"/>
<reference key="NSMixedImage" ref="434332216"/>
<string key="NSAction">_popUpItemAction:</string>
<reference key="NSTarget" ref="186846319"/>
</object>
</array>
<reference key="NSMenuFont" ref="473291212"/>
</object>
Expand Down Expand Up @@ -620,6 +630,7 @@
<reference ref="12195002"/>
<reference ref="401829720"/>
<reference ref="268064417"/>
<reference ref="36233711"/>
</array>
<reference key="parent" ref="186846319"/>
</object>
Expand Down Expand Up @@ -674,6 +685,11 @@
<reference key="object" ref="268064417"/>
<reference key="parent" ref="494084656"/>
</object>
<object class="IBObjectRecord">
<int key="objectID">50</int>
<reference key="object" ref="36233711"/>
<reference key="parent" ref="494084656"/>
</object>
</array>
</object>
<dictionary class="NSMutableDictionary" key="flattenedProperties">
Expand Down Expand Up @@ -710,12 +726,13 @@
<string key="4.IBPluginDependency">com.apple.InterfaceBuilder.CocoaPlugin</string>
<string key="48.IBPluginDependency">com.apple.InterfaceBuilder.CocoaPlugin</string>
<string key="49.IBPluginDependency">com.apple.InterfaceBuilder.CocoaPlugin</string>
<string key="50.IBPluginDependency">com.apple.InterfaceBuilder.CocoaPlugin</string>
</dictionary>
<dictionary class="NSMutableDictionary" key="unlocalizedProperties"/>
<nil key="activeLocalization"/>
<dictionary class="NSMutableDictionary" key="localizations"/>
<nil key="sourceID"/>
<int key="maxID">49</int>
<int key="maxID">50</int>
</object>
<object class="IBClassDescriber" key="IBDocument.Classes">
<array class="NSMutableArray" key="referencedPartialClassDescriptions">
Expand Down

0 comments on commit 0ddbd84

Please sign in to comment.