• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: NSSteppers... oh and NSColorWell's
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: NSSteppers... oh and NSColorWell's


  • Subject: Re: NSSteppers... oh and NSColorWell's
  • From: Scott Anguish <email@hidden>
  • Date: Sat, 2 Nov 2002 23:30:17 -0500

On Saturday, November 2, 2002, at 11:03 PM, Chris Giddings wrote:

Hey guys,

I'm still relatively new to Cocoa. I'm attempting to get an NSStepper
to increment the contents of a textField to its left, but I'm uncertain
on how to get this to work properly. The textField will have numeric
values in it.


This depends on how you want to handle this.. do you want the text field to simply display the field? or allow editing as well?

You could hook the target of the NSStepper up to a method in your code that got the incremented number, and stuck it in the text field... (updating any method variable you needed to keep track of it in as well)..

Also, I'm attempting to get an NSColorWell to spit back to me a value
which can be interpreted in to a hex value. This needs to be done in
order for my application to allow for easy input of color values for
internet development purposes.


What you want here is to convert an NSColor to a hexRepresentation..

In our Cocoa Programming (www.cocoaprogramming.net) we have an example that is an HTMLColorPicker... so, pulling from that..

Basically, what you need to do is take whatever color you end up getting back from the NSColorWell, force it to RGB color space, and then convert it.

This is in Mail, but the technique is right... :-)


@interface NSColor(htmlcolorversion)
- (NSString *)hexRepresentation;
@end

@implementation NSColor(htmlcolorversion)

- (NSString *)hexRepresentation
{
NSString *hexString;
NSColor *forcedRBGColor;
float red, green, blue;
int scaledRed, scaledGreen, scaledBlue;

// convert the color to calibrated RGB
red=[forcedRBGColor redComponent];
green=[forcedRBGColor greenComponent];
blue=[forcedRBGColor blueComponent];

// scale the color components to the web rgb color range
scaledRed = red * 255;
scaledBlue = blue * 255;
scaledGreen = green * 255;

forcedRBGColor=[self colorUsingColorSpaceName:NSCalibratedRGBColorSpace];
hexString=[NSString stringWithFormat:@"#xxx",scaledRed,scaledGreen,scaledBlue];

return hexString;

}

going the other way (from hex colors to RGB) would require converting the hex strings to integers, and then dividing by 255 and creating a new calibratedRGBColor with the components.
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.
References: 
 >NSSteppers... oh and NSColorWell's (From: Chris Giddings <email@hidden>)

  • Prev by Date: NSSteppers... oh and NSColorWell's
  • Next by Date: (Part 3) Thread-safety concerns
  • Previous by thread: NSSteppers... oh and NSColorWell's
  • Next by thread: Re: NSSteppers... oh and NSColorWell's
  • Index(es):
    • Date
    • Thread