In this example, we will show you how to use the CreativeEditor SDK’s CreativeEngine to manage spot colors in the editor API.
Functions#
public func findAllSpotColors() -> [String]Queries the names of currently set spot colors previously set with setSpotColor.
- Returns: The names of set spot colors.
public func getSpotColor(name: String) -> RGBAQueries the RGB representation set for a spot color. If the value of the queried spot color has not been set yet, returns the default RGB representation (of magenta). The alpha value is always 1.0.
- name:: The name of a spot color.
- Returns: A result holding the four color components.
public func getSpotColor(name: String) -> CMYKQueries the CMYK representation set for a spot color. If the value of the queried spot color has not been set yet, returns the default CMYK representation (of magenta).
- name:: The name of a spot color.
- Returns: A result holding the four color components.
public func setSpotColor(name: String, r: Float, g: Float, b: Float)Sets the RGB representation of a spot color. Use this function to both create a new spot color or update an existing spot color.
- name: The name of a spot color.
- r: The red color component in the range of 0 to 1.
- g: The green color component in the range of 0 to 1.
- b: The blue color component in the range of 0 to 1.
public func setSpotColor(name: String, c: Float, m: Float, y: Float, k: Float)Sets the CMYK representation of a spot color. Use this function to both create a new spot color or update an existing spot color.
- name: The name of a spot color.
- c: The cyan color component in the range of 0 to 1.
- m: The magenta color component in the range of 0 to 1.
- y: The yellow color component in the range of 0 to 1.
- k: The key color component in the range of 0 to 1.
public func removeSpotColor(name: String) throwsRemoves a spot color from the list of set spot colors.
- name:: The name of a spot color.
Full Code#
Here’s the full code:
// Create a spot color with an RGB color approximation.engine.editor.setSpotColor(name: "Red", r: 1.0, g: 0.0, b: 0.0)
// Create a spot color with a CMYK color approximation.// Add a CMYK approximation to the already defined 'Red' spot color.engine.editor.setSpotColor(name: "Yellow", c: 0.0, m: 0.0, y: 1.0, k: 0.0)engine.editor.setSpotColor(name: "Red", c: 0.0, m: 1.0, y: 1.0, k: 0.0)
// List all defined spot colors.engine.editor.findAllSpotColors() // ["Red", "Yellow"]
// Retrieve the RGB color approximation for a defined color.// The alpha value will always be 1.0.let rgbaSpotRed: RGBA = engine.editor.getSpotColor(name: "Red")
// Retrieve the CMYK color approximation for a defined color.let cmykSpotRed: CMYK = engine.editor.getSpotColor(name: "Red")
// Retrieving the approximation of an undefined spot color returns magenta.let cmykSpotUnknown: CMYK = engine.editor.getSpotColor(name: "Unknown") // Returns CMYK values for magenta.
// Removes a spot color from the list of defined spot colors.try engine.editor.removeSpotColor(name: "Red")