Platforms to show: All Mac Windows Linux Cross-Platform

Back to NSColorMBS class.

NSColorMBS.CGColorHandle as Integer

Type Topic Plugin Version macOS Windows Linux iOS Targets
method Cocoa Drawing MBS MacBase Plugin 12.3 ✅ Yes ❌ No ❌ No ✅ Yes All
Converts NSColor to CGColor.

Return value may be an approximation in some cases, so there isn't guaranteed round-trip fidelity.
Available on Mac OS X 10.8.

NSColorMBS.colorSpace as NSColorSpaceMBS

Type Topic Plugin Version macOS Windows Linux iOS Targets
method Cocoa Drawing MBS MacBase Plugin 9.8 ✅ Yes ❌ No ❌ No ❌ No Desktop, Console & Web
Returns an object representing the color space of the receiver.
Example
Var b as NSColorMBS = NSColorMBS.blueColor

MsgBox b.colorSpace.localizedName

An object representing a color space. The returned NSColorSpace object may represent a custom color space.

Calling this method raises an exception if the receiver is not based on a color space represented by an NSColorSpace object—specifically, colors designated by NSNamedColorSpace and NSPatternColorSpace. If you are unsure about a color object, convert it to an equivalent NSColorSpace-based object before calling this method. Color objects created with color-space names NSCalibratedWhiteColorSpace, NSCalibratedBlackColorSpace, NSCalibratedRGBColorSpace, NSDeviceWhiteColorSpace, NSDeviceBlackColorSpace, NSDeviceRGBColorSpace, NSDeviceCMYKColorSpace, or NSCustomColorSpace—or with the NSColorSpace class methods corresponding to these names—are safe to use with this method. See "About Color Spaces" in Color Programming Topics for Cocoa for a list of these corresponding methods.

NSColorMBS.colorUsingColorSpace(colorSpace as NSColorSpaceMBS) as NSColorMBS

Type Topic Plugin Version macOS Windows Linux iOS Targets
method Cocoa Drawing MBS MacBase Plugin 9.8 ✅ Yes ❌ No ❌ No ❌ No Desktop, Console & Web
Returns a new color object representing the color of the receiver in the specified color space.
Example
Var b as NSColorMBS = NSColorMBS.blueColor
Var c as NSColorMBS = b.colorUsingColorSpace(NSColorSpaceMBS.deviceRGBColorSpace)

MsgBox b.description

space: The color space of the new NSColor object.

Returns the new NSColor object. This method converts the receiver's color to an equivalent one in the new color space. Although the new color might have different component values, it looks the same as the original. Returns nil if conversion is not possible.

If the receiver's color space is the same as that specified in space, this method returns the same NSColor object.

NSColorMBS.colorUsingColorSpaceName(colorSpace as string) as NSColorMBS

Type Topic Plugin Version macOS Windows Linux iOS Targets
method Cocoa Drawing MBS MacBase Plugin 9.8 ✅ Yes ❌ No ❌ No ❌ No Desktop, Console & Web
Creates and returns an NSColor whose color is the same as the receiver's, except that the new NSColor is in the specified color space.

colorSpace: The name of the color space containing the new NSColor object. If colorSpace is "", the most appropriate color space is used.

The new NSColor object or nil if the specified conversion cannot be done.

NSColorMBS.colorUsingType(type as Integer) as NSColorMBS

Type Topic Plugin Version macOS Windows Linux iOS Targets
method Cocoa Drawing MBS MacBase Plugin 18.4 ✅ Yes ❌ No ❌ No ❌ No Desktop, Console & Web
Convert the color to a color of different type.

Return nil if conversion is not possible.

NSColorMBS.colorWithAlphaComponent(alpha as Double) as NSColorMBS

Type Topic Plugin Version macOS Windows Linux iOS Targets
method Cocoa Drawing MBS MacBase Plugin 9.8 ✅ Yes ❌ No ❌ No ✅ Yes All
Creates and returns an NSColor object that has the same color space and component values as the receiver, but the specified alpha component.
Example
Var b as NSColorMBS = NSColorMBS.blueColor.colorWithAlphaComponent(0.5)
MsgBox b.description // shows "NSCalibratedRGBColorSpace 0 0 1 0.5"

alpha: The opacity value of the new NSColor object.

Returns a new NSColor object. If the receiver's color space doesn't include an alpha component, the receiver is returned.

A subclass with explicit opacity components should override this method to return a color with the specified alpha.

Some examples using this method:

NSColorMBS.colorWithSystemEffect(systemEffect as Integer) as NSColorMBS

Type Topic Plugin Version macOS Windows Linux iOS Targets
method Cocoa Drawing MBS MacBase Plugin 18.4 ✅ Yes ❌ No ❌ No ❌ No Desktop, Console & Web
Returns a color representing the base color with a system defined effect applied to it.

This color is safe to create before draw time, as the resolution of the final color only happens when being set, retrieving its CGColor, resolving with colorWithType, etc. The return color type is named.
Available on MacOS 10.14 or newer.

NSColorMBS.Components as Double()

Type Topic Plugin Version macOS Windows Linux iOS Targets
method Cocoa Drawing MBS MacBase Plugin 9.8 ✅ Yes ❌ No ❌ No ❌ No Desktop, Console & Web
Returns the components of the receiver as an array.
Example
Var b as NSColorMBS = NSColorMBS.blueColor
Var c(-1) as Double = b.Components
Var lines(-1) as string

for each d as Double in c
lines.Append str(d)
next

MsgBox Join(lines) // shows 0 0 1 1

You can invoke this method on NSColor objects created from custom color spaces to get the individual floating point components, including alpha. Raises an exception if the receiver doesn't have floating-point components. To find out how many components are in the components array, send the receiver a numberOfComponents message.

NSColorMBS.Constructor(c as color)

Type Topic Plugin Version macOS Windows Linux iOS Targets
method Cocoa Drawing MBS MacBase Plugin 17.1 ✅ Yes ❌ No ❌ No ✅ Yes All
Initializes the color with generic colorspace.
Example
Var r as NSColorMBS = NSColorMBS.redColor
Var c as color = &cFF0000
Var n as new NSColorMBS(c)

Break // check debugger

See also:

NSColorMBS.Constructor(red as Double, green as Double, blue as Double, alpha as Double = 1.0)

Type Topic Plugin Version macOS Windows Linux iOS Targets
method Cocoa Drawing MBS MacBase Plugin 17.1 ✅ Yes ❌ No ❌ No ✅ Yes All
Initializes the color with generic colorspace.

Pass values in range from 0.0 to 1.0.

See also:

The items on this page are in the following plugins: MBS MacBase Plugin.


The biggest plugin in space...