如何查找UITextView行数 [英] How to find UITextView number of lines

查看:98
本文介绍了如何查找UITextView行数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我必须找到 UITextView 的行数。在 UITextView 上没有可用的属性,如 numberOfLines 。我使用以下公式,但它不起作用。有人对此有所了解吗?

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;


推荐答案

如果您使用的是iOS 3,则需要使用前导属性:

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

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

如果您使用的是iOS 4,则需要使用 lineHeight property:

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

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

而且,正如@thomas指出的那样,如果你需要一个确切的结果,要小心四舍五入。

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

这篇关于如何查找UITextView行数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆