从 NSBundle 中读取rtf文本文件的内容,然后用UITextView展示:
NSURL *url = [[NSBundle mainBundle] URLForResource:@"Test.rtf" withExtension:nil];
NSMutableAttributedString *attributedText = [[NSMutableAttributedString alloc]
initWithFileURL:url
options:@{}
documentAttributes:nil
error:nil];
// 返回相关联的字体,文字样式,并适当缩放用户选择的内容大小类别的一个实例。见UIFontDescriptor.h的完整列表
// + (UIFont *)preferredFontForTextStyle:(NSString *)style NS_AVAILABLE_IOS(7_0);
[attributedText addAttribute:NSFontAttributeName
value:[UIFont preferredFontForTextStyle:UIFontTextStyleBody]
range:NSMakeRange(0, attributedText.length)];
UITextView *tView = [[UITextView alloc] initWithFrame:CGRectMake(10, 10, 300, 400)
textContainer:nil];
tView.attributedText = attributedText;
[self.view addSubview:tView];