问题
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:
- Subclass
NSTextFieldCell
; - Override
- (void)drawWithFrame:(NSRect)cellFrame
,- (void)drawInteriorWithFrame:
(if need) method(s) ofNSCell
and put all drawing code you need to those methods. Don't forget to callsuper
implementation; - Set
Class
field ofNSTextFieldCell
inInterface Builder
to your subclass; - Setup
border
in.xib
file to(I don't know name of this border);
- Turn off
Draw Background
;
来源:https://stackoverflow.com/questions/5519512/nstextfield-placeholder-text-doesnt-show-unless-editing