Are NSColors like tungsten and steel also available?
-
26-09-2019 - |
Question
I know Cocoa gives you whiteColor
, blackColor
, darkGrayColor
, but do they also have the colors from in Apple's color panel? With colors like "Snow", "Tungsten", "Steel", "Tin" ? Or should I create those myself?
Solution
You want NSColorList. The one named “Crayons” corresponds to the crayon box in the Color Panel.
OTHER TIPS
You should find the rgb values for those colors and make your own NSColor. Documentation for NSColor from rgb here
You can add Categories
to NSColor
and make ANY color with ANY name you want… So you need a make 2 files… NSColor+YourCategories.h
…
#import <Cocoa/Cocoa.h>
@interface NSColor (YourCategories) // Tag in () is "yours" to name,
+ (NSColor *) MAUVE;
@end
and an aptly named NSColor+YourCategories.m
file
#import "NSColor+YourCategories.h"
@implementation NSColor (YourCategories)
+ (NSColor *) MAUVE { static NSColor* MAUVE = nil; if( MAUVE == nil )
MAUVE = [NSColor colorWithDeviceRed:0.712 green:0.570 blue:0.570 alpha:1.000];r
return MAUVE;
}
The simply
#import NSColor+YourCategories.h
on any page which you want to be able to refer to your named colors, like…
[[self window]setBackGroundColor: [NSColor MAUVE]];
∀Ⓛ∃✖