[英]NSTextField doesn't show when I set AttributedString placeholder
我正在嘗試自定義我的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
。 第一個沒有出現在任何地方。
怎么了?
提前致謝。
您要設置兩次相同的emailTextField ...
[[[self emailTextField] cell] setPlaceholderAttributedString:emailPlaceholderString];
[[[self emailTextField] cell] setPlaceholderString:@"Password"];
(這是解決問題還是只是問題中的錯誤?)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.