NSTextField placeholder text doesn't show unless editing
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:
- 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
;
精彩评论