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

前端 未结 13 1480
逝去的感伤
逝去的感伤 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条回答
  •  Happy的楠姐
    2020-11-27 03:59

    I think that you can try to use NSLayoutManager:

    NSLayoutManager *layoutManager = [textView layoutManager];
    unsigned numberOfLines, index, numberOfGlyphs =
            [layoutManager numberOfGlyphs];
    NSRange lineRange;
    for (numberOfLines = 0, index = 0; index < numberOfGlyphs; numberOfLines++){
        (void) [layoutManager lineFragmentRectForGlyphAtIndex:index
                effectiveRange:&lineRange];
        index = NSMaxRange(lineRange);
    }
    

    Ref

    CountLines

提交回复
热议问题