【问题标题】:get a lineHeight in uitextview在 uitextview 中获取 lineHeight
【发布时间】:2011-01-18 10:06:17
【问题描述】:
我想在 uitextview 中获得一个行高,我必须在我的应用程序中使用它来计算。我使用了sizeWithFont:constrainedToSize:lineBreakMode: 方法,但它给出了textview 中所有行的高度。
我知道 Three20 库,但我不知道如何使用它。有人知道怎么做吗??
Three20 库可以保存使用吗?因为我已经阅读了一些关于 Iphone 拒绝应用程序的文章,因为使用了该库。
真的需要你的帮助..
谢谢大家
问候,
-risma-
【问题讨论】:
标签:
ipad
uitextview
three20
css
【解决方案1】:
终于...
我有我的答案...谢谢你的回答 Prasanna,我有很多使用它的想法,:)
在这种情况下,我不使用框架中的大小,但我使用 textview 中的 contentSize,这里是我制作的代码:
NSString *head = [textView.text substringToIndex:textView.selectedRange.location];
//--get the size of this part--
CGSize initialSize = [head sizeWithFont:textView.font constrainedToSize:textView.contentSize];
NSUInteger startOfLine = [head length];
NSRange delimiter = [head rangeOfCharacterFromSet:[NSCharacterSet characterSetWithCharactersInString:textView.text] options:NSBackwardsSearch range:NSMakeRange(0, startOfLine)];
//--substring the part after cursor position--
NSString *tail = [head substringFromIndex:delimiter.location];
//--gets the size of this part--
CGSize lineSize = [tail sizeWithFont:textView.font forWidth:textView.contentSize.width lineBreakMode:UILineBreakModeWordWrap];
它已经为我完成了,也许它也可以帮助你,Prasanna