我认为每次占位符出现/消失时,您都必须设置字体。设置文本字段委托并添加此代码...
func textField(textField: UITextField, shouldChangeCharactersInRange range: NSRange, replacementString string: String) -> Bool {
let length = (textField.text?.characters.count)! + (string.characters.count - range.length)
// If there is text in the text field
if (length > 0) {
// Set textfield font
textField.font = UIFont(name: "OpenSans Bold", size: 18)
} else {
// Set textfield placeholder font (or so it appears)
textField.font = UIFont(name: "OpenSans Regular", size: 18)
}
return true;
}
Obj-C:
- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string
{
// If there is text in the text field
if (textField.text.length + (string.length - range.length) > 0) {
// Set textfield font
textField.font = [UIFont fontWithName:@"OpenSans Bold" size:18];
} else {
// Set textfield placeholder font (or so it appears)
textField.font = [UIFont fontWithName:@"OpenSans Regular" size:18];
}
return YES;
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句