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

时间:2024-10-03 13:35:08

一,效果图。

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

二,工程图。

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

三,代码。

RootViewController.m

【代码笔记】iOS-读取一段文字
#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.
}
【代码笔记】iOS-读取一段文字