当NSTextField(Label)绑定到带有绑定的控制器选择时,我已经为多值标记,无选择标记等指定了占位符值,它会绘制一个灰色的文本,该颜色不能很好地显示在一个黑暗的背景。
有没有办法更改用于显示占位符文字的文字颜色?
答案 0 :(得分:15)
使用指定所需颜色的属性字符串,如下所示:
NSDictionary *blueDict = [NSDictionary dictionaryWithObject: [NSColor blueColor]
forKey: NSForegroundColorAttributeName];
NSAttributedString *blueString = [[[NSAttributedString alloc] initWithString: @"test"
attributes: blueDict] autorelease];
然后您可以直接设置占位符属性字符串:
[[field cell] setPlaceholderAttributedString: blueString];
或通过绑定来完成,例如:
[field2 bind: @"value" toObject: [NSUserDefaults standardUserDefaults]
withKeyPath: @"foo"
options: [NSDictionary dictionaryWithObject: blueString forKey: NSNullPlaceholderBindingOption]];
答案 1 :(得分:0)
您可以尝试制作自己的“占位符”。我的意思是你可以使用你想要的任何文本参数在文本字段上显示标签。