Inherits from | |
Conforms to | |
Framework | /System/Library/Frameworks/AppKit.framework |
Availability | Available in Mac OS X v10.0 and later. |
Companion guide | |
Declared in | NSColorList.h |
An NSColorList
object is an ordered list of NSColor
objects, identified by keys. Instances of NSColorList
, or more simply color lists, are used to manage named lists of NSColor
instances. 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.
Returns an array of all color lists found in the standard color list directories.
+ (NSArray *)availableColorLists
An array of NSColorList
objects representing all of the color lists found in the standard color list directories, including color catalogs (lists of colors identified only by name). Color lists created at runtime aren’t included in this list unless they’re saved into one of the standard color list directories.
NSColorList.h
Searches the array that’s returned by availableColorLists
and returns the color list with the given name.
+ (NSColorList *)colorListNamed:(NSString *)name
The name of the color list to retrieve. This name must not include the “.clr
” suffix.
The color list with the specified name or nil
if no such color list exists.
NSColorList.h
Returns an array of the keys by which the NSColor
objects are stored in the receiver.
- (NSArray *)allKeys
An array of NSString
objects containing all the keys by which the NSColor
objects are stored in the receiver.
The length of this array equals the number of colors, and its contents are arranged according to the ordering specified when the colors were inserted.
NSColorList.h
Returns the NSColor
object associated with the given key.
- (NSColor *)colorWithKey:(NSString *)key
The key for which to retrieve the color.
The color associated with the given key or nil
if there is none.
NSColorList.h
Initializes and returns the receiver, registering it under the given name if it isn’t in use already.
- (id)initWithName:(NSString *)name
The name under which to register the color list. Specify @”” if you don’t want a name.
The initialized color list.
This method invokes initWithName:fromFile:
with a fromFile:
argument of nil
, indicating that the color list doesn’t need to be initialized from a file. Note that this method does not add the color list to availableColorLists
until the color list is saved into the user’s path with writeToFile:
with a value of nil
.
NSColorList.h
Initializes and returns the receiver, registering it under the given name if it isn’t in use already.
- (id)initWithName:(NSString *)name fromFile:(NSString *)path
The name of the file for the color list (minus the “.clr
” extension). Specify @”” if you don’t want a name.
The full path to the file for the color list. A nil
path indicates the color list should be initialized with no colors.
Note that this method does not add the color list to availableColorLists
until the color list is saved into the user’s path with writeToFile:
with a value of nil
.
NSColorList.h
Inserts the specified color at the specified location in the receiver.
- (void)insertColor:(NSColor *)color key:(NSString *)key atIndex:(NSUInteger)location
The color to add to the color list.
The key with which to associate the color.
The location in the color list at which to place the specified color. Locations are numbered starting with 0.
If the list already contains a color with the same key at a different location, it’s removed from the old location. This method posts NSColorListDidChangeNotification
to the default notification center. It raises NSColorListNotEditableException
if the color list isn’t editable.
NSColorList.h
Returns a Boolean value indicating whether the receiver can be modified.
- (BOOL)isEditable
YES
if the color list can be modified; otherwise NO
. This result depends on the source of the list: If it came from a write-protected file, this method returns NO
.
NSColorList.h
Returns the name of the receiver.
- (NSString *)name
The name of the receiver.
NSColorList.h
Removes the color associated with the specified key from the receiver.
- (void)removeColorWithKey:(NSString *)key
The key for which to remove the color.
This method does nothing if the receiver doesn’t contain the key. This method posts NSColorListDidChangeNotification
to the default notification center. It raises NSColorListNotEditableException
if the receiver is not editable.
NSColorList.h
Removes the file from which the list was created, if the file is in a standard search path and owned by the user.
- (void)removeFile
The receiver is removed from the list of available color lists returned by availableColorLists
. If there are no outstanding references to the color list, this method might deallocate the object as well.
NSColorList.h
Associates the specified NSColor
object with the specified key.
- (void)setColor:(NSColor *)color forKey:(NSString *)key
The color to associate with the given key.
The key.
If the list already contains key, this method sets the corresponding color to color; otherwise, it inserts color at the end of the list by invoking insertColor:key:atIndex:
.
NSColorList.h
Saves the receiver to a file at the specified path.
- (BOOL)writeToFile:(NSString *)path
The path at which to save the color list. If path is a directory, the receiver is saved in a file named listname.clr
in that directory (where listname is the name with which the receiver was initialized).
If path includes a filename, this method saves the file under that name. If path is nil
, the file is saved as listname.clr
in the user’s private colorlists directory.
NSColorList.h
Posted whenever a color list changes. The notification object is the NSColorList
object that changed. This notification does not contain a userInfo dictionary.
NSColorList.h
Last updated: 2007-02-28