I want that colour value using Cocoa:
Thanks.
Go to the Apple menu and go to “System Preferences” Choose the “General” preference panel. Near the top of the panel pulldown the menu next to “Highlight color:” and pick the color to change to.
You can use the methods on the NSColor
class to get the user's preferences.
The Accessing System Colors section in Color Programming Topics states that
NSColor has a number of methods that return system colors: colors controlled by user preferences. These colors—currently only
selectedControlColor
andselectedTextBackgroundColor
—should be used by developers who want to create custom controls or subclass existing controls while honoring the user's color preferences.
The NSColor for the users Highlight color will be the control color selectedControlColor
As far as I know you first have to convert the selectedControlColor to a known color space as it is not based on the NSNamedColorSpace.
NSNamedColorSpace = Catalog name and color name components The components of this color space are indexes into lists or catalogs of prepared colors. The catalogs of named colors come with lookup tables that are able to generate the correct color on a given device.
Generally, it is recommended that you use calibrated (or generic) color spaces instead of device color spaces. The colors in device color spaces can vary widely from device to device, whereas calibrated color spaces usually result in a reasonably accurate color. Device color spaces, on the other hand, might yield better performance under certain circumstances, so if you know for certain the device that will render or capture the color, use a device color space instead.
A code example
NSColor *aColor = [[NSColor selectedControlColor] colorUsingColorSpaceName:NSCalibratedRGBColorSpace];
if (aColor) {
NSLog(@" Red %f, Green %f, Blue %f, Alpha %f,", aColor.redComponent,aColor.greenComponent,aColor.blueComponent,aColor.alphaComponent);
}
see the Creating and Converting Color Spaces section in the Color Programming Topics
Which will give you more idea of how this works and finding how many components a colour has.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With