美文网首页
iOS placeholder的属性文字 那看到的

iOS placeholder的属性文字 那看到的

作者: 师景福 | 来源:发表于2016-09-26 09:41 被阅读16次

一.直接设置textFiled的placeholder的属性文字

NSMutableDictionary *dict = [NSMutableDictionary dictionary];

dict[NSForegroundColorAttributeName] = [UIColor whiteColor];

dict[NSFontAttributeName] = textFiled.font;

textFiled.attributedPlaceholder = [[NSAttributedString alloc]initWithString:@“占位文字”attributes:dict];

二.画出属性文字

-(void)drawPlaceholderInRect:(CGRect)rect{

NSMutableDictionary *dict = [NSMutableDictionary dictionary];

dict[NSForegroundColorAttributeName] = [UIColor whiteColor];

dict[NSFontAttributeName] = textFiled.font;

//设置self.placeholder的位置

CGFloat placeholderW = rect.size.width;

CGFloat placeholderH = textFiled.font.lineHeight;

CGFloat placeholderX = 0;

CGFloat placeholderY = (rect.size.height - placeholderH)*0.5;

[textFiled.placeholder drawInRect:CGRectMake(placeholderX, placeholderY, placeholderW, placeholderH) withAttributes:dict];

}

三.取出系统自带的label设置

UILabel *placeholderLabel = [textFiled valueForKey:@"placeholderLabel"];

placeholderLabel.textColor = [UIColor yellowColor];

[textFiled setValue:[UIColor yellowColor] forKeyPath:@"placeholderLabel.textColor"];

2.设置光标的颜色

一.通过xib或者storyboard设置Tint属性的颜色

二. textFiled.tintColor = [UIColor whiteColor];

相关文章

网友评论

      本文标题:iOS placeholder的属性文字 那看到的

      本文链接:https://www.haomeiwen.com/subject/gxxoettx.html