Lorsque l'utilisateur appuie sur la touche [Retour], il doit afficher le numéro. Comme les numéros de série [1,2 etc] pour chaque ligne. Y a-t-il un moyen de le faire?Comment faire la numérotation automatique sur UITextview lorsque vous appuyez sur la touche de retour dans swift
code suivant j'ai essayé
func textView(_ textView: UITextView, shouldChangeTextIn range: NSRange, replacementText text: String) -> Bool {
var textview_text_nssring = textView.text as NSString
// Add "1" when the user starts typing into the text field
if (range.location == 0 && textView.text.isEmpty) {
if text == "\n" {
textView.text = "1."
let cursor = NSMakeRange(range.location + 3, 0)
textView.selectedRange = cursor
return false
}
else {
textView.text = NSString(format: "1. %@", text) as String
}
}
return true
}
Montrez-nous ce que vous avez essayé. –
@NiravD updated.thanks – Lydia