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

前端 未结 13 1470
逝去的感伤
逝去的感伤 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:08

    You need to use the lineHeight property, and font lineHeight:

    Objective-C

    int numLines = txtview.contentSize.height / txtview.font.lineHeight;
    

    Swift

    let numLines = (txtview.contentSize.height / txtview.font.lineHeight) as? Int
    

    I am getting correct number of lines, hope it help you also.

提交回复
热议问题