Question

When the NSTextField (Label) is bound to a controller selection with bindings, and I have specified placeholder values for the Multiple Values Marker, No Selection Marker, etc it draws the text with a gray color that does not show up well on a dark background.

Is there a way to change the text color it uses to display the placeholder text?

Was it helpful?

Solution

Use an attributed string specifying the color you want, like this:

NSDictionary *blueDict = [NSDictionary dictionaryWithObject: [NSColor blueColor]
                        forKey: NSForegroundColorAttributeName];
NSAttributedString *blueString = [[[NSAttributedString alloc] initWithString: @"test"
                                attributes: blueDict] autorelease];

Then you can either set the placeholder attributed string directly:

[[field cell] setPlaceholderAttributedString: blueString];

or do it through a binding, for example:

[field2 bind: @"value" toObject: [NSUserDefaults standardUserDefaults]
        withKeyPath: @"foo"
        options: [NSDictionary dictionaryWithObject: blueString forKey: NSNullPlaceholderBindingOption]];

OTHER TIPS

you can try to make your own "palceholder". I mean your can show a label over your textfield with any text patameters you want.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top