支持中文的简单文本文件输入保存相关

涉及很多个阶段,主要包括 :

A; 文件创建,只是后缀名的问题,比较容易解决

B:内容 编辑阶段 ,这个比较复杂

C:内容保存到文件,基本使用 NSData?

D: 文件再次被打开?txt file---》进入到不可编辑模式了 。。。

 

转自:http://www.raywenderlich.com/4147/how-to-create-a-simple-magazine-app-with-core-text

code referense sample:https://github.com/omnigroup/OmniGroup/tree/master/Frameworks/OmniUI/iPad/Examples/TextEditor/--- newest,but too heavy

https://github.com/jonasschnelli/I7CoreTextExample ---oldest, maybe as a starter up

ios:

1。CoreText.framework 引用添加

2。#import <CoreText/CoreText.h>

3. CTFrmedraw/CTFramesetter/CGPathAndRef

---简单测试就发现画出来的core text文字是在底部而且是反的。很多底层的API采用的坐标系是Y轴反向的,在使用CT和uiview混合使用中记得要注意

先把内容坐标旋转:

Let’s fix the content orientation! Add the following code just after this line “CGContextRef context = UIGraphicsGetCurrentContext();”:

// Flip the coordinate system
CGContextSetTextMatrix(context, CGAffineTransformIdentity);
CGContextTranslateCTM(context, 0, self.bounds.size.height);
CGContextScaleCTM(context, 1.0, -1.0);

This is very simple code, which just flips the content by applying a transformation to the view’s context. Just copy/paste it each time you do drawing with CT.

 

You create a CTFramesetter reference and you provide it with NSAttributedString. At this point, an instance of CTTypesetter is automatically created for you, a class that manages your fonts. Next you use the CTFramesetter to create one or more frames in which you will be rendering text.

CTFramesetter /cttypesetter/ctline/ctrun几个基本的类型关系理解清楚。

自己需要完成类似超文本的解析,在一个复杂的string中完成这些内容,这个是否意味着其实这类txt文件即使copy出来,普通的文本编辑器也是无法直接编写的?

a tag will set the style of the text after the tag, the style will be applied until a new tag is found. The text markup will look like this:

These are <font color="red">red<font color="black"> and
<font color="blue">blue <font color="black">words.

支持中文的简单文本文件输入保存相关_第1张图片

 


You create a CTFramesetter reference and you provide it with NSAttributedString. At this point, an instance of CTTypesetter is automatically created for you, a class that manages your fonts. Next you use the CTFramesetter to create one or more frames in which you will be rendering text.You create a CTFramesetter reference and you provide it with NSAttributedString. At this point, an instance of CTTypesetter is automatically created for you, a class that manages your fonts. Next you use the CTFramesetter to create one or more frames in which you will be rendering text.CoreText.frameworkYou’ll learn how to:You’ll learn how to:Let’s fix the content orientation! Add the following code just after this line “CGContextRef context = UIGraphicsGetCurrentContext();”

// Flip the coordinate system
CGContextSetTextMatrix(context, CGAffineTransformIdentity);
CGContextTranslateCTM(context, 0, self.bounds.size.height);
CGContextScaleCTM(context, 1.0, -1.0);

This is very simple code, which just flips the content by applying a transformation to the view’s context. Just copy/paste it each time you do drawing with CT.

 

  • lay formatted text down on the screen;
  • fine tune the text’s appearance;
  • add images inside the text content;
  • and finally create a magazine app, which loads text markup to easily control the formatting of the rendered text.

 

  • lay formatted text down on the screen;
  • fine tune the text’s appearance;
  • add images inside the text content;
  • and finally create a magazine app, which loads text markup to easily control the formatting of the rendered text.
转自: http://www.raywenderlich.com/4147/how-to-create-a-simple-magazine-app-with-core-text转自: http://www.raywenderlich.com/4147/how-to-create-a-simple-magazine-app-with-core-text转自:http://www.raywenderlich.com/4147/how-to-create-a-simple-magazine-app-with-core-text转自:http://www.raywenderlich.com/4147/how-to-create-a-simple-magazine-app-with-core-text转自:http://www.raywenderlich.com/4147/how-to-create-a-simple-magazine-app-with-core-text转自:http://www.raywenderlich.com/4147/how-to-create-a-simple-magazine-app-with-core-text

注意 : :

大视频的压缩 似乎是自动的呢 


http://blog.csdn.net/andypan1314/article/details/7614469

注意 : : 

中文应用都要遇到一个很头疼的问题:文字编码,汉字的 GBK 和 国际通用的 UTF-8 的互相转化稍一不慎,就会满屏乱码。下面介绍 UTF-8 和 GBK 的 NSString 相互转化的方法

从 GBK 转到 UTF-8

用 NSStringEncoding enc = CFStringConvertEncodingToNSStringEncoding(kCFStringEncodingGB_18030_2000) ,然后就可以用initWithData:encoding来实现。

从 UTF-8 转到 GBK

CFStringConvertEncodingToNSStringEncoding(kCFStringEncodingGB_18030_2000),得到的enc却是kCFStringEncodingInvalidId。

没关系,试试 NSData *data=[nsstring dataUsingEncoding:-2147482063];


注意:必须使用kCFStringEncodingGB_18030_2000这个字符集,那个kCFStringEncodingGB_2312_80试了也不行。

你可能感兴趣的:(支持中文的简单文本文件输入保存相关)