nscolor

NSColor | Creating Color from RGB Values

ⅰ亾dé卋堺 提交于 2021-02-17 20:30:35
问题 In my application, i will get RGB Values as a unsigned character so it will not be more then 255, I am using NSColor API to create the color and will make use of it to draw the font and background color, this is the function that i have written +(NSColor *)getColorFromRGB:(unsigned char)r blue:(unsigned char)b green:(unsigned char)g { CGFloat rFloat = r/255.0; CGFloat gFloat = g/255.0; CGFloat bFloat = b/255.0; // return [NSColor colorWithCalibratedRed:((float)r/255.0) green:((float)g/255.0)

NSColor | Creating Color from RGB Values

纵然是瞬间 提交于 2021-02-17 20:28:20
问题 In my application, i will get RGB Values as a unsigned character so it will not be more then 255, I am using NSColor API to create the color and will make use of it to draw the font and background color, this is the function that i have written +(NSColor *)getColorFromRGB:(unsigned char)r blue:(unsigned char)b green:(unsigned char)g { CGFloat rFloat = r/255.0; CGFloat gFloat = g/255.0; CGFloat bFloat = b/255.0; // return [NSColor colorWithCalibratedRed:((float)r/255.0) green:((float)g/255.0)

NSColor systemColor not changing when dark/light mode switched

孤街醉人 提交于 2020-05-29 08:49:05
问题 I'm trying to change the colour of an image with the switching of dark/light mode in an NSViewController . I'm using this code for changing the colour of the image: - (NSImage *)image:(NSImage *)image withColour:(NSColor *)colour { NSImage *img = image.copy; [img lockFocus]; [colour set]; NSRect imageRect = NSMakeRect(0, 0, img.size.width, img.size.height); NSRectFillUsingOperation(imageRect, NSCompositingOperationSourceAtop); [img unlockFocus]; return img; } I've tried calling this method

cocoa: Read pixel color of NSImage

那年仲夏 提交于 2020-01-01 11:49:17
问题 I have an NSImage . I would like to read the NSColor for a pixel at some x and y. Xcode seems to thing that there is a colorAtX:y: method on NSImage , but this causes a crash saying that there is no such method for NSImage. I have seen some examples where you create an NSBitmapImageRep and call the same method on that, but I have not been able to successfully convert my NSImage to an NSBitmapImageRep . The pixels on the NSBitmapImageRep are different for some reason. There must be a simple

Count colors in image: `NSCountedSet` and `colorAtX` are very slow

时间秒杀一切 提交于 2019-12-20 06:01:35
问题 I'm making an OS X app which creates a color scheme from the main colors of an image. As a first step, I'm using NSCountedSet and colorAtX to get all the colors from an image and count their occurrences: func sampleImage(#width: Int, height: Int, imageRep: NSBitmapImageRep) -> (NSCountedSet, NSCountedSet) { // Store all colors from image var colors = NSCountedSet(capacity: width * height) // Store the colors from left edge of the image var leftEdgeColors = NSCountedSet(capacity: height) //

Conditional categories in Mountain Lion

感情迁移 提交于 2019-12-17 20:26:11
问题 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? 回答1: NSColor *_NSColor_colorWithCGColor_

NSColorWell not sending action on click?

心不动则不痛 提交于 2019-12-12 16:17:17
问题 Inside my .xib, I've placed an NSColorWell inside an NSView , and connected an IBAction in the controller to the NSColorWell 's Sent Actions (via File's Owner). I figured I would respond to a click in my controller and send activate to bring up the NSColorPanel . But unlike other my controls, I'm not getting the IBAction called. Clicking invokes a drag action on the color. I noticed this control doesn't derive from NSActionCell (like all my other controls). What's the proper control that is

iOS use of NSColor versus UIColor?

大兔子大兔子 提交于 2019-12-10 02:27:20
问题 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? 回答1: There is no such thing as NSColor in iOS. UIColor is what you should use. NSColor only exists as a OSX class. 回答2: As Nate says,

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

▼魔方 西西 提交于 2019-12-06 04:43:19
问题 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? 回答1: I don't know how this actually works, but I found a way to

Convert NSColor to RGB

倖福魔咒の 提交于 2019-12-06 03:53:38
问题 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