开发者

NSTextField placeholder text doesn't show unless editing

开发者 https://www.devze.com 2023-02-21 05:04 出处:网络
I set the placeholder text of m开发者_如何学运维y NSTextField in Interface Builder, but the placeholder text doesn\'t show until I click inside the text field to edit it.Have you tried setting the pla

I set the placeholder text of m开发者_如何学运维y NSTextField in Interface Builder, but the placeholder text doesn't show until I click inside the text field to edit it.


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

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


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.


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

    NSTextField placeholder text doesn't show unless editing

    (I don't know name of this border);
  5. Turn off Draw Background;
0

精彩评论

暂无评论...
验证码 换一张
取 消