indragie
indragie

Reputation: 18122

NSTextField placeholder text doesn't show unless editing

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.

Upvotes: 16

Views: 11614

Answers (3)

Lexandr
Lexandr

Reputation: 689

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;

Upvotes: -2

GJ Nilsen
GJ Nilsen

Reputation: 715

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.

Upvotes: 22

Johann Dirdal
Johann Dirdal

Reputation: 1090

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

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

Upvotes: 28

Related Questions