我正在尝试自定义一点 my NSTextFields
,第一步是自定义placeholder
.
我想更改占位符颜色,我正在尝试通过这种方式:
- (void)awakeFromNib {
// Color for placeholder in NSTextField - Color: #cdc9c1
NSColor *placeholderColor = [NSColor colorWithCalibratedRed:0.80f green:0.78f blue:0.75f alpha:1.0f];
NSDictionary *placeholderAttributeDict = [NSDictionary dictionaryWithObject:placeholderColor forKey:NSForegroundColorAttributeName];
NSAttributedString *emailPlaceholderString = [[NSAttributedString alloc] initWithString:@"Email" attributes:placeholderAttributeDict];
// NSAttributedString *passPlaceholderString = [[NSAttributedString alloc] initWithString:@"Password" attributes:placeholderAttributeDict];
// NSTextField Email attributes
[[self emailTextField] setDrawsBackground:NO];
[[self emailTextField] setBordered:NO];
[[[self emailTextField] cell] setPlaceholderAttributedString:emailPlaceholderString];
// NSTextField Password attributes
[[self passTextField] setDrawsBackground:NO];
[[self passTextField] setBordered:NO];
[[[self emailTextField] cell] setPlaceholderString:@"Password"];
}
如您所见,第一个占位符NSTextField
是由NSAttributedString
我尝试指定颜色的位置建立的。第二个占位符NSTextField
只是一个NSString
.
当我运行应用程序时,它只显示第二个NSTextField
. 第一个没有出现在任何地方。
怎么了?
提前致谢。