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

一,效果图。

【代码笔记】读取一段文字_第1张图片

二,工程图。

【代码笔记】读取一段文字_第2张图片

三,代码。

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.
}
复制代码

 

你可能感兴趣的:(【代码笔记】读取一段文字)