NSTextField placeholder text doesn't show unless editing

前端 未结 3 2012
清歌不尽
清歌不尽 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: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;

提交回复
热议问题