我创建了两个UITextView
。一个用于行号,一个用于编辑。但是我似乎无法让前者显示行数。这是我到目前为止所写的内容,我确信我犯了一个错误,只是不确定在哪里。
var previousRect = CGRectZero
var lineArray = ["1"]
func textViewDidChange(textView: UITextView) {
let pos = editorView.endOfDocument
let currentRect = editorView.caretRectForPosition(pos)
if(currentRect.origin.y > previousRect.origin.y){
//new line reached, write your code
var i = 0
i += 1
lineArray.append("\(i)")
let numberOfLinesString = "\(lineArray)"
lineNumbering.text = "\(lineArray)\n"
}
previousRect = currentRect
}