我将文本字段的限制设置为300
时出错class ViewController: UIViewController, UITextFieldDelegate {
func textField(textField: UITextField, shouldChangeCharactersInRange range: NSRange, replacementString string: String) -> Bool {
let newLength = count(textField.text!.utf16) + count(string.utf16) - range.length
return newLength <= 300 // Bool
}
}