美文网首页
修改iOS placeholder的属性

修改iOS placeholder的属性

作者: tinaH | 来源:发表于2016-07-30 13:45 被阅读37次

方法一

NSMutableAttributedString * placehoder= [[NSMutableAttributedString alloc]initWithString:@"手机号"];

[placehoder setAttributes:@{NSForegroundColorAttributeName :[UIColor whiteColor]} range:NSMakeRange(1, 1)];

self.phoneField.attributedPlaceholder = placehoder;

方法二

//通过这个方法重写placeholder

- (void)drawPlaceholderInRect:(CGRect)rect

{

[self.placeholder drawInRect:CGRectMake(0, 10, rect.size.width, 25) withAttributes:@{

NSForegroundColorAttributeName :[UIColor grayColor], NSFontAttributeName:self.font}];

}

方法三使用kvc

static NSString * const LJHplaceholderColor = @"_placeholderLabel.textColor";

@implementation TextFieldWhite

- (void)awakeFromNib

{

self.tintColor = self.textColor;

[self resignFirstResponder];

}

- (BOOL)becomeFirstResponder

{

[self setValue:[UIColor whiteColor] forKeyPath:LJHplaceholderColor];

return [super becomeFirstResponder];

}

- (BOOL)resignFirstResponder

{

[self setValue:self.textColor forKeyPath:LJHplaceholderColor];

return [super resignFirstResponder];

}

相关文章

网友评论

      本文标题:修改iOS placeholder的属性

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