Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
769 views
in Technique[技术] by (71.8m points)

iphone - How to find UITextView number of lines

I have to find the number of lines of a UITextView. There is no property available, like anumberOfLines, on UITextView. I use the following formula, but it not doesn't work. Does anybody have an idea about this?

int numLines = txtview.contentSize.height/txtview.font.lineHeight;
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...