16
votes

I set the placeholder text of my NSTextField in Interface Builder, but the placeholder text doesn't show until I click inside the text field to edit it.

3
That sounds like the exact opposite of what should happen. The placeholder text should disappear when the field is being edited. How have you set up your NSTextField? Is it bound to anything? Note that the placeholder string will only be shown if the stringValue of the text field is nil or @"". - Stephen Poletto
There is no binding for the text field and its empty too. I've edited my post to show screenshots of the editing/not editing states. - indragie
I have the same issue, did you find your answer? - Nathan H

3 Answers

28
votes

Have you tried setting the placeholder through code? for example something like this:

    [[textField cell] setPlaceholderString:@"hello"];
20
votes

Have you bound the NSTextField data in Interface Builder? If so, you have to set the "Multiple Values Placeholder", "No Selection Placeholder" and "Null Placeholder" in the bindings tab in your Utilities inspector. While youre at it, you could set the "No Applicable Placeholder" as well.

-2
votes

This is how I solve this problem:

  1. Subclass NSTextFieldCell;
  2. Override - (void)drawWithFrame:(NSRect)cellFrame, - (void)drawInteriorWithFrame: (if need) method(s) of NSCell and put all drawing code you need to those methods. Don't forget to call super implementation;
  3. Set Class field of NSTextFieldCell in Interface Builder to your subclass;
  4. Setup border in .xib file to border (I don't know name of this border);
  5. Turn off Draw Background;