[英]Multiple placeholder text color in iOS
Is it possible to have multiple color text in a placeholder? 占位符中可以有多个彩色文本吗?
For example 例如
Write Text - I will prepend this.
写文本-我将在此之前。
"Write Text" will be black, while "I will prepend this." “写文本”将为黑色,而“我将以此为准”。 will be grey.
将是灰色的。
Multiple Textfiled placeholder in ios. ios中的多个Textfiled占位符。
self.txt_First.attributedPlaceholder = [self String:@"Brewery (Sierra Nevada)" Range:7];
In above textfield first seven character is red and other are gray. 在上面的文本字段中,前七个字符为红色,其他为灰色。
Use the below mehod for setting multiple color. 使用以下方法设置多种颜色。
-(NSAttributedString *)String:(NSString *)str Range:(int )Rannge
{
NSMutableAttributedString *attString =
[[NSMutableAttributedString alloc]
initWithString:str];
[attString addAttribute: NSForegroundColorAttributeName
value: [UIColor redColor]
range: NSMakeRange(0,Rannge)];
[attString addAttribute: NSForegroundColorAttributeName
value: [UIColor graycolor]
range: NSMakeRange(Rannge + 1,str.length - Rannge -1)];
return attString;
}
Multiple placeholder color Output : 多种占位符颜色输出:
I have Simple way for this . 我对此有简单的方法。
Add UILabel
in UITextField
below and set UITextField
clearColor
.and set your UILabel
text as you required and set that text color same as placeholder color . 在下面的
UITextField
中添加UILabel
并设置UITextField
clearColor
并根据需要设置UILabel
文本,并将该文本颜色设置为与占位符color相同。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.