【代码笔记】iOS-读取一段文字

一,效果图。

二,工程图。

三,代码。

RootViewController.m

复制代码
#import "RootViewController.h"

@interface RootViewController ()

@end

@implementation RootViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    //初始化textView
    [self addTextView];

}
#pragma -mark -functions
-(void)addTextView
{
    UITextView *textView = [[UITextView alloc]initWithFrame:CGRectMake(0, 100, 320, 200)];
    textView.backgroundColor = [UIColor redColor];
    textView.textAlignment=NSTextAlignmentLeft;
    NSString * str = [NSString stringWithContentsOfFile:[[NSBundle mainBundle]pathForResource:@"脑筋急转弯" ofType:@"txt"] encoding:NSUTF8StringEncoding error:nil];
    textView.text = str;
    [self.view addSubview:textView];

}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
复制代码

 

原文地址:https://www.cnblogs.com/yang-guang-girl/p/5159299.html