二.Text Kit中重要的一些对象 image.jpg 图中主要表现NSTextContainer, NSLayoutManager, NSTextStorage之间的关系。 Text storage对应着NSTextStorage类。该类定义了Text Kit扩展文本处理系统中的基本存储机制。 NSTextStorage继承自NSmutableAttributedString,主要用来存储文本的字符和相关属性。 另外,当NSTextStorage中的字符或属性发生了改变,会通知NSLayoutManager,进而做到文本内容的显示更新。 其实总结下来就是,一个文字需要先创建一个容器对象(NSTextContainer),然后还需要创建一个文字的存储对象(NSTextStorage)。
②、创建有占位视图的UITextView,主要涉及NSTextStorage、NSLayoutManager、NSTextContainer、UIBezierPath几个类,主要代码如下: NSString NSForegroundColorAttributeName :[UIColor whiteColor],NSParagraphStyleAttributeName : paragraphStyle }; //文本存储 NSTextStorage *textStorage = [[NSTextStorage alloc] initWithString:title]; [textStorage addAttributes:attributeDictionary
在TextKit框架中,提供了几个类分别对应处理上述的必要条件: 1.NSTextStorage对应要渲染展示的内容。 2.UITextView对应要渲染的视图。 TextKit进行文本布局流程 个人理解,TextKit主要用于更精细的处理文本布局以及进行复杂的图文混排布局,使用TextKit进行文本的布局展示十分繁琐,首先需要将显示内容定义为一个NSTextStorage * storage = [[NSTextStorage alloc]initWithString:@"The NSTextContainer class defines a region where * storage = [[NSTextStorage alloc]initWithString:@"The NSTextContainer class defines a region where NSTextStorage实际上是继承自NSMutableAttributedString。
NSTextAttachment对象,常用于文字图片混排 NSParagraphStyleAttributeName 设置文本段落排版格式,取值为 NSParagraphStyle 对象 2、NSTextStorage NSTextStorage本身继承与NSMutableAttributedString,这两者唯一的重大不同点是文本存储包含了一个方法来发送内容改变的通知,它是以attributed string的形式保存需要渲染的文本 通常你需要创建NSTextStorage的子类来在文本改变时进行文本显示样式的更新。
的常用属性: //text kit工具 NSTextContainer *_textContainer; NSLayoutManager *_layoutManager; NSTextStorage