nscolor

Exactly matching the background of a selected NSMenuItem

帅比萌擦擦* 提交于 2019-12-05 08:54:34
问题 I am creating a custom view for an NSMenuItem . In order to draw the background when selected, I adapted a couple of lines from the CustomMenus sample. The CustomMenus sample has: [[NSColor alternateSelectedControlColor] set]; NSRectFillUsingOperation(dirtyRect, NSCompositeSourceOver); .. and I am using the selectedMenuItemColor because the alternateSelectedControlColor was a solid color and it did not look very good: [[NSColor selectedMenuItemColor] set]; NSRectFillUsingOperation(dirtyRect,

iOS use of NSColor versus UIColor?

浪尽此生 提交于 2019-12-05 01:07:54
What's the difference between UIColor and NSColor , and when would one use each? I came across NSColor while trying to figure out UIColor uses for attributed strings in iOS. I understand the use of UIColor for the UIKit and such, but I don't think NSColor is really useful for this kind of thing. Has NSColor fallen into disuse with regards to iOS programming? There is no such thing as NSColor in iOS. UIColor is what you should use. NSColor only exists as a OSX class. As Nate says, NSColor is OSX only. If you ran across a mention of it in the docs on NSAttributedString, it's probably

How does +[NSColor selectedMenuItemColor] magically draw a gradient?

喜夏-厌秋 提交于 2019-12-04 11:07:51
I'm implementing a custom NSMenuItem view that shows a highlight as the user mouses over it. To do this, the code calls NSRectFill after setting [NSColor selectedMenuItemColor] as the active color. However, I noticed that the result is not simply a solid color — it actually draws a gradient instead. Very nice, but wondering how this "magic" works — i.e. if I wanted to define my own color that didn't just draw solid, how would I? I don't know how this actually works, but I found a way to replicate the behavior with custom gradients (or any other drawing operations). The "trick" is to use a

Is there a conventional method for inverting NSColor values?

[亡魂溺海] 提交于 2019-12-04 08:58:58
问题 I'm looking for a way to invert arbitrary NSColor values at runtime, and there doesn't appear to be any built-in method to do so. I will be using a category to extend NSColor as follows: NSColor * invertedColor = [someOtherColor inverted]; Here is the category method prototype that I am using: @implementation NSColor (MyCategories) - (NSColor *)inverted { NSColor * original = [self colorUsingColorSpaceName: NSCalibratedRGBColorSpace]; return ...? } @end Can anyone fill in the blanks? This

Convert NSColor to RGB

落爺英雄遲暮 提交于 2019-12-04 08:06:01
I'm trying to convert an NSColor to RGB, but it seems to give an entirely incorrect result: NSColor *testColor = [NSColor colorWithCalibratedWhite:0.65 alpha:1.0]; const CGFloat* components = CGColorGetComponents(testColor.CGColor); NSLog(@"Red: %f", components[0]); NSLog(@"Green: %f", components[1]); NSLog(@"Blue: %f", components[2]); NSLog(@"Alpha: %f", CGColorGetAlpha(testColor.CGColor)); I get back : red = 0.65 - green = 1.0 - blue = 0.0 and alpha is 1.0 - which results in an entirely different color. (It should be gray, now it's green). Am I doing something wrong? You need to convert the

Exactly matching the background of a selected NSMenuItem

大憨熊 提交于 2019-12-03 21:58:40
I am creating a custom view for an NSMenuItem . In order to draw the background when selected, I adapted a couple of lines from the CustomMenus sample. The CustomMenus sample has: [[NSColor alternateSelectedControlColor] set]; NSRectFillUsingOperation(dirtyRect, NSCompositeSourceOver); .. and I am using the selectedMenuItemColor because the alternateSelectedControlColor was a solid color and it did not look very good: [[NSColor selectedMenuItemColor] set]; NSRectFillUsingOperation(dirtyRect, NSCompositeSourceOver); Using selectedMenuItemColor is better, but it's still not exactly the same as a

Is there a conventional method for inverting NSColor values?

血红的双手。 提交于 2019-12-03 01:34:47
I'm looking for a way to invert arbitrary NSColor values at runtime, and there doesn't appear to be any built-in method to do so. I will be using a category to extend NSColor as follows: NSColor * invertedColor = [someOtherColor inverted]; Here is the category method prototype that I am using: @implementation NSColor (MyCategories) - (NSColor *)inverted { NSColor * original = [self colorUsingColorSpaceName: NSCalibratedRGBColorSpace]; return ...? } @end Can anyone fill in the blanks? This doesn't have to be perfect, but I would like it to make some sense. i.e.: [[[NSColor someColor] inverted]

NSTabView with background color

旧城冷巷雨未停 提交于 2019-11-30 15:58:15
As discussed elsewhere, NSTabView does not have a setBackgroundColor method and subclassing NSTabView and using an drawRect to control it does no longer work - as it does not paint the top 10%, the bit just below the segmented control button. Now I am a bit surprised by the amounts of work arounds I had to do solving this; see code: https://github.com/dirkx/CustomizableTabView/blob/master/CustomizableTabView/CustomizableTabView.m and am wondering if i went down the wrong path. And how to do this better & simpler: The NSSegmentStyleTexturedSquare seems to yield me a semi-transparent segmented

NSTabView with background color

安稳与你 提交于 2019-11-29 23:06:33
问题 As discussed elsewhere, NSTabView does not have a setBackgroundColor method and subclassing NSTabView and using an drawRect to control it does no longer work - as it does not paint the top 10%, the bit just below the segmented control button. Now I am a bit surprised by the amounts of work arounds I had to do solving this; see code: https://github.com/dirkx/CustomizableTabView/blob/master/CustomizableTabView/CustomizableTabView.m and am wondering if i went down the wrong path. And how to do

Conditional categories in Mountain Lion

笑着哭i 提交于 2019-11-28 12:32:12
Mountain Lion introduced new APIs , some of which we had implemented as categories in our project. For examples, we have a category NSColor+CGColorAdditions that implemented CGColor and colorWithCGColor: for NSColor . These methods have been added in Mountain Lion. Ideally, we would like to use these categories if the client OS is older than Mountain Lion, and not use them if it's Mountain Lion. How can we do this? Or is there a better alternative? NSColor *_NSColor_colorWithCGColor_(Class self, SEL cmd, CGColorRef cgColor) { // make an NSColor outta `cgColor` and return it return nsColor; } /