当我们设置placeHoder的字体过大的时候,他会和控件的位置居中,但是如果字体偏小,它相对输入框的位置就有点偏上,最后自己找到了解决办法,避免重写的麻烦,希望与大家一起交流一下,代码如下
NSMutableParagraphStyle *style = [field.defaultTextAttributes[NSParagraphStyleAttributeName] mutableCopy];
style.minimumLineHeight = field.font.lineHeight - (field.font.lineHeight - [UIFont systemFontOfSize:14.0].lineHeight) / 2.0;
field.attributedPlaceholder = [[NSAttributedString alloc] initWithString:@"YourTextField Placeholder text"
attributes:@{
NSForegroundColorAttributeName: [UIColor colorWithRed:255/255.0f green:255/255.0f blue:255/255.0f alpha:0.7f],
NSFontAttributeName : [UIFont systemFontOfSize:14.0],
NSParagraphStyleAttributeName : style
}
];