用UITextView加载rtfd文件
效果
说明
使用此方法可以实现十分简易的富文本显示效果,包括图文混排等等效果。
源码
// // ViewController.m // Rtfd // // Created by YouXianMing on 15/9/10. // Copyright (c) 2015年 ZiPeiYi. All rights reserved. // #import "ViewController.h" @interface ViewController () { UITextView *_textView; } @end @implementation ViewController - (void)viewDidLoad { [super viewDidLoad]; NSString *path = [[NSBundle mainBundle] pathForResource:@"demo" ofType:@"rtfd"]; NSAttributedString *string = [[NSAttributedString alloc] initWithFileURL:[NSURL fileURLWithPath:path] options:nil documentAttributes:nil error:nil]; _textView = [[UITextView alloc] initWithFrame:self.view.bounds]; _textView.backgroundColor = [UIColor clearColor]; _textView.attributedText = string; _textView.editable = NO; _textView.selectable = NO; _textView.bounces = YES; _textView.showsHorizontalScrollIndicator = NO; _textView.showsVerticalScrollIndicator = NO; [self.view addSubview:_textView]; } @end
细节
富文本中的图片
对比图