开发者

How to count line breaks (not /n) in an UITextView?

开发者 https://www.devze.com 2023-02-15 16:20 出处:网络
I would like to count how many automatic line breaks (not returns the user enters) I have in a text displayed in UITextView which is, for argument\'s sake, 200 pixels in width and 460 pixels in length

I would like to count how many automatic line breaks (not returns the user enters) I have in a text displayed in UITextView which is, for argument's sake, 200 pixels in width and 460 pixels in length (see attached screen shot!).

I have found this when looking for a solution:

stringSize = [t sizeWithFont:f constrainedToSize:CGSizeMake(320, 10000)
lineBreakMode:UILineBreakModeWordWrap];

But this won't give me an int number for 'invisible' line brakes, will it? Also, I don't understand the 320, 10000 ... 320 is for the width I guess and would need to be changed to 200 in my case. But why 10.000 ??

Sorry, but I'm a beginner and this doesn't make much开发者_如何学编程 sense to me...

How to count line breaks (not /n) in an UITextView?


The CGSizeMake statement is to provide bounds in order to compute the size of text. It is common to constrain the width and to set a high value for the height to let enough space for the computation.

In your case, the width will be 200 and you can leave the height to 10000 as long as the text is not too long.

0

精彩评论

暂无评论...
验证码 换一张
取 消