self.passTF.attributedPlaceholder = [self changePlaceholderWithTextField:self.passTF withString:@"请输入密码"];
- (NSMutableAttributedString *)changePlaceholderWithTextField:(UITextField *)textField withString:(NSString *)string{
//设置光标颜色
textField.tintColor = [UIColor whiteColor];
textField.textColor = [UIColor whiteColor];
//placeholder前面加入空格
textField.leftView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 42/2/1.5, 0)];
textField.leftViewMode = UITextFieldViewModeAlways;
NSMutableAttributedString *attributeString = [[NSMutableAttributedString alloc]initWithString:string];
if (SCREEN_WIDTH == 320) {
[attributeString addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:12.0] range:NSMakeRange(0, string.length)];
}else{
[attributeString addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:14.0] range:NSMakeRange(0, string.length)];
}
//设置placeholder字体的颜色
[attributeString addAttribute:NSForegroundColorAttributeName value:[UIColor colorWithRed:152/255.0 green:152/255.0 blue:152/255.0 alpha:1] range:NSMakeRange(0, string.length)];
return attributeString;
}
网友评论