16

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.

Cœur
  • 37,241
  • 25
  • 195
  • 267
indragie
  • 18,002
  • 16
  • 95
  • 164
  • 1
    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 Apr 01 '11 at 23:47
  • 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 Apr 02 '11 at 00:52
  • I have the same issue, did you find your answer? – Nathan H Dec 12 '11 at 16:49

3 Answers3

28

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

    [[textField cell] setPlaceholderString:@"hello"];
Johann Dirdal
  • 1,100
  • 6
  • 12
20

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.

GJ Nilsen
  • 695
  • 9
  • 27
-2

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;
Lexandr
  • 679
  • 1
  • 6
  • 22