![](/img/trans.png)
[英]How can I programmatically know if a NSTextField is currently displaying a placeholder ?
[英]How to control the text color of an NSTextField when it is displaying a placeholder marker?
當NSTextField(Label)綁定到帶有綁定的控制器選擇時,我為多值標記,無選擇標記等指定了占位符值,它會在深色背景上繪制一個灰色的文本。
有沒有辦法更改用於顯示占位符文本的文本顏色?
使用指定所需顏色的屬性字符串,如下所示:
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]];
你可以嘗試制作自己的“掌控者”。 我的意思是你可以用你想要的任何文字參數在你的文本區域上顯示一個標簽。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.