Detect moment when newline starts in UITextView

后端 未结 8 861
甜味超标
甜味超标 2020-12-08 16:23

I try to detect when carriage goes at new line in UITextView. I can detect it by comparison total later width with UITextView width:

CGSize size = [textView.         


        
8条回答
  •  Happy的楠姐
    2020-12-08 17:16

    For Swift use this

    previousRect = CGRectZero
    
     func textViewDidChange(textView: UITextView) {
    
            var pos = textView.endOfDocument
            var currentRect = textView.caretRectForPosition(pos)
            if(currentRect.origin.y > previousRect?.origin.y){
                //new line reached, write your code
            }
            previousRect = currentRect
    
        }
    

提交回复
热议问题