在TextField中放置PlaceHolder
我想在下面的图像的文本框占位符文本中添加必填字段标记请build议我我完全困惑如何做到这一点
您可以使用 :
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];
这看起来像:
注意 :您可以根据您的强度计算而不是硬编码范围。
如果您是从xib创buildTextField,请单击文本字段,然后转到属性检查器,并将占位符名称填充到占位符文本字段
试试这个…..
[tfSubject setValue:[UIColor colorWithRed:249.0/255.0 green:204.0/255.0 blue:88.0/255.0 alpha:1.0] forKeyPath:@"_placeholderLabel.textColor"];