uma*_*eed 9 objective-c nslayoutmanager uitextview nsattributedstring ios
我正在为应用程序编写文本编辑器.我正在使用UITextView
请参阅示例代码以加载文本视图.
// Read text from file (around 300k - 400k words)
NSError *error = nil;
NSString *contentOfFile = [[NSString alloc] initWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"17254" ofType:@"txt"]
encoding:NSUTF8StringEncoding
error:&error];
// Attributes for text
UIFont *font = [UIFont fontWithName:@"Baskerville" size:36.0f];
NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];
paragraphStyle.alignment = NSTextAlignmentJustified;
NSDictionary *attributes = [[NSDictionary alloc] initWithObjectsAndKeys:font, NSFontAttributeName,
[UIColor blackColor], NSForegroundColorAttributeName,
paragraphStyle, NSParagraphStyleAttributeName, nil];
// Create attributed string
NSAttributedString *attributedString = [[NSAttributedString alloc] initWithString:contentOfFile attributes:attributes];
// Assign to text view
self.textView.attributedText = attributedString;
Run Code Online (Sandbox Code Playgroud)
文字大小约为400k字.
我面临以下问题.
滚动文本变得太慢,因为我向下滚动和一些时间应用程序崩溃由于内存问题.我认为iOS将文本视图向下滚动时将渲染的文本图像保存在其内存中,但是当我向上滚动到顶部时它会释放内存.
如果我点击"全选",则选择文本需要花费太多时间,文本选择后滚动变得很差,有些时候应用程序因内存问题而崩溃,因为它的内存增加了.我认为iOS在其内存中生成完整文本的图像(就好像它对用户可见),然后选择完整的文本并保留其图像直到选择完成.选择完成后,应用程序保留的内存下降.
显示大文本的另一种方法是使用多个textview并将文本分配给可见textview,就像UITableView一样,但这会增加复杂性,因为我必须重新计算UItextView的layoutManager的每个textChanged委托调用所需的textview数量. .
任何机构都知道如何在UITextView中以更好的性能显示大型属性文本.
任何猜测iPages应用程序如何工作,因为它在区域可见范围内显示文本.
| 归档时间: |
|
| 查看次数: |
1657 次 |
| 最近记录: |