【发布时间】:2015-09-26 14:44:55
【问题描述】:
我目前遇到了类似SO question 中描述的问题(目前没有可接受的答案),除非选择了文本字段,否则我的文本字段的占位符文本不可见。
我已将NSTextField 子类化(代码如下):
@interface CustomTextField : NSTextField
@property (nonatomic, strong) IBInspectable NSImage *backgroundImage;
@end
@implementation CustomTextField
- (void)awakeFromNib
{
[self setDrawsBackground:NO];
}
- (void)drawRect:(NSRect)rect
{
NSImage *backgroundImage = self.backgroundImage;
[super drawRect:rect];
[self lockFocus];
[backgroundImage drawInRect:rect fromRect:rect operation:NSCompositeSourceOver fraction:1.0];
[self unlockFocus];
}
@end
我在Interface Builder中将我的文本字段的类设置为CustomTextField,并设置占位符文本如下所示:
从下面的屏幕截图中可以看出,占位符文本仅在选择文本字段时可见...
文本字段一:
文本字段二:
无论用户是否选择了占位符文本,是否有人知道如何使占位符文本可见?谢谢!
【问题讨论】:
标签: objective-c macos cocoa interface-builder nstextfield