[Return] 키를 누르면 번호가 표시됩니다. 각 줄에 대한 일련 번호 [1,2 etc]를 좋아해. 그럴 수있는 방법이 있니?신속한 반환 키를 누를 때 UITextview에서 자동 번호 매기기를 만드는 방법
다음 코드는 내가 현재 행 번호를 하나 Int
VAR를 선언하고 이런 식으로 같은 shouldChangeTextIn range
내부에 사용
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
}
우리가 시도한 것을 보여주십시오. –
@NiravD updated.thanks – Lydia