开发者

Are NSColors like tungsten and steel also available?

开发者 https://www.devze.com 2022-12-26 07:47 出处:网络
I know C开发者_如何学Goocoa 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\"

I know C开发者_如何学Goocoa 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?


You want NSColorList. The one named “Crayons” corresponds to the crayon box in the Color Panel.


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]];

∀Ⓛ∃✖

0

精彩评论

暂无评论...
验证码 换一张
取 消