NSTextField placeholder text doesn't show unless editing

前端 未结 3 2010
清歌不尽
清歌不尽 2021-01-17 09:30

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条回答
  • 2021-01-17 10:06

    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.

    0 讨论(0)
  • 2021-01-17 10:07

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

        [[textField cell] setPlaceholderString:@"hello"];
    
    0 讨论(0)
  • 2021-01-17 10:28

    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;
    0 讨论(0)
提交回复
热议问题