Counting the number of lines in a UITextView, lines wrapped by frame size

前端 未结 13 1413
逝去的感伤
逝去的感伤 2020-11-27 03:42

I wanted to know when a text is wrapped by the frame of the text view is there any delimiter with which we can identify whether the text is wrapped or not.

For insta

相关标签:
13条回答
  • 2020-11-27 04:16

    You need to consider textView.textContainerInset, also need to round the calculated value since line number definitely is an integer

    float rawLineNumber = (textView.contentSize.height - textView.textContainerInset.top - textView.textContainerInset.bottom) / textView.font.lineHeight;
    int finalLineNumber = round(rawLineNumber)
    

    In real case, you may see following result rawLineNumber = 3.008099 finalLineNumber = 3 (3 lines)

    0 讨论(0)
提交回复
热议问题