用UITextView加载rtfd文件

用UITextView加载rtfd文件

 

效果

用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

 

细节

用UITextView加载rtfd文件

用UITextView加载rtfd文件

用UITextView加载rtfd文件

 

富文本中的图片

用UITextView加载rtfd文件

 

对比图

用UITextView加载rtfd文件

 

相关文章:

  • 2021-08-17
  • 2021-04-11
  • 2022-12-23
  • 2022-12-23
  • 2021-06-03
  • 2021-11-25
猜你喜欢
  • 2022-01-13
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-01-04
  • 2022-12-23
  • 2021-08-04
相关资源
相似解决方案