我想在文本字段占位符文本中添加必填字段标记,如下图所示,请建议我我完全感到困惑
最佳答案
您可以使用 :
NSMutableAttributedString *attriButedString = [[NSMutableAttributedString alloc]initWithString:@"Mandatory*"];
[attriButedString addAttribute:NSForegroundColorAttributeName
value:[NSColor lightGrayColor]
range:NSMakeRange(0, 9)];
[attriButedString addAttribute:NSForegroundColorAttributeName
value:[NSColor redColor]
range:NSMakeRange(9, 1)];
[[self.textField cell] setPlaceholderAttributedString:attriButedString];
如下所示:
注意:您可以根据字符串长度来计算,而不是硬编码范围。