我正在为应用程序编写文本编辑器.我正在使用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字.
我面临以下问题. …
objective-c nslayoutmanager uitextview nsattributedstring ios