Textview: Limitar caracteres y saltos de linea

var limitOfCharacters: Int! var allowMultiline = true func textView(_ textView: UITextView, shouldChangeTextIn range: NSRange, replacementText text: String) -> Bool { //Avoiding break lines if self.allowMultiline == false { guard text.rangeOfCharacter(from: CharacterSet.newlines) == nil else { textView.resignFirstResponder() return false } } //Avoiding over limit if let limit = self.limitOfCharacters { return textView.text.characters.count + text.characters.count - range.length <= limit } return true }

Be the first to comment

You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.