NSTextField placeholder text doesn't show unless editing

て烟熏妆下的殇ゞ 提交于 2019-12-01 13:54:23

问题


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. Anyone else having this issue?

Thanks

EDIT: Screenshots. Here's what the field looks like when I'm not editing it:

Not editing http://cl.ly/2a0R1h1p2A082g1t1b3q/Screen_Shot_2011-04-01_at_6.51.25_PM.png

And this is what it looks like when I'm editing it:

Editing http://cl.ly/1c2d1U233R3j3k0M2E2Q/Screen_Shot_2011-04-01_at_6.51.32_PM.png


回答1:


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

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



回答2:


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.




回答3:


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

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


来源:https://stackoverflow.com/questions/5519512/nstextfield-placeholder-text-doesnt-show-unless-editing

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!