如何在ios中限制UITextView中的内容 [英] How to limit the content in UITextView in ios
问题描述
我想在不同视图的TextViews中加载长文本。当文本到达文本视图的末尾时,应将文本分成页面。下一个textview必须从文本的继续开始。
我已经经历了很多答案。但是所有都指定了在输入数据时限制文本内容。我想在TextView中显示分页数据。并且不会有任何输入或编辑。所以关于它的委托方法将不起作用。
我试图加载固定长度的文本。但是当段落的数量不同时,这是不正确的。
所以我想要找到的是,当文本到达textview的容量或获取结束时得到通知textview的容量根据no lines / no.of字符。有没有办法做到这一点?
更新
按照我得到的评论,我搜索了很多,并达到了NSTextStorage,NSTextLayoutManager和NSTextContainer
我找到了这个链接,这将有助于轻松实现分页
I want to load long text in TextViews of different Views. The text should be divided to pages when it reaches end of the textviews. And the next textview must start with the continuation of the text.
I have gone through a lot of answers. But all specifies about limiting text content when entering data. I want to display paged data in TextView. And there wont be any entering or editing in it. So the delegate methods regarding that won't work.
I tried to load text of fixed length. but it is not correct when the no.of paragraphs varies.
So what i am trying to find is , get notified when the the text reaches end of textview's capacity or getting the capacity of textview as per no lines/ no.of characters. Is there any way to do this ???
Update
As per the comments i have got, i searched a lot and reached at NSTextStorage, NSTextLayoutManager and NSTextContainer
I have found this link which will help to easily implement pagination
http://sketchytech.blogspot.co.uk/2013/11/paging-and-paginating-easy-way-with.html
I this example they have created 4 objects using loop. It can be said as they have splitted the string to 4 parts and displayed in 4 uitextviews of a scrollview.
I am trying to set a condition to split to textcontainers according to the length of string. I trying to create a condition by considering the total length of main string & the text displayed in textviews.
But each textview' text length is same as the total length of the main string. So how i could get the length text displayed in each textcontainer of textview ????
解决方案Option 2 does work in iOS with the proper parameters.
NSAttributedString *attrStr = ... // your attributed string CGFloat width = 300; // whatever your desired width is CGRect rect = [attrStr boundingRectWithSize:CGSizeMake(width, 10000) options:NSStringDrawingUsesLineFragmentOrigin | NSStringDrawingUsesFontLeading context:nil];
Without the proper values for the options parameter you will get the wrong height.
got this answer from here
这篇关于如何在ios中限制UITextView中的内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!