我想在文本字段占位符文本中添加强制字段标记,如下图所示,请告诉我我完全搞不懂怎么做。

发布于 2013-12-06 12:11:31
您可以使用:
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];如下所示:

注释:你可以根据你的字符串长度来计算,而不是硬编码的范围。
发布于 2013-12-06 12:15:13

如果要从xib创建TextField,请单击“文本”字段,转到属性检查器,然后在占位符文本feild中填写占位符名称。
发布于 2013-12-06 12:33:40
试试这个..。
[tfSubject setValue:[UIColor colorWithRed:249.0/255.0 green:204.0/255.0 blue:88.0/255.0 alpha:1.0] forKeyPath:@"_placeholderLabel.textColor"];https://stackoverflow.com/questions/20423541
复制相似问题