我認爲你需要時常出現佔位時間/消失設置字體。設置文本字段委託,並添加以下代碼...
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;
}
@EricD:我只是給了我很久以前使用的代碼。不過,我明白你的觀點。答案已更新。 – Nishant
謝謝。它正在工作。 –