How to find UITextView number of lines

后端 未结 3 1220
说谎
说谎 2020-12-15 12:44

I have to find the number of lines of a UITextView. There is no property available, like anumberOfLines, on UITextView. I use the f

3条回答
  •  离开以前
    2020-12-15 12:56

    If you are using iOS 3, you need to use the leading property:

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

    If you are using iOS 4, you need to use the lineHeight property:

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

    And, as @thomas pointed out, be careful of rounding if you need an exact result.

提交回复
热议问题