nstextstorage

How to replace a text attachment with a custom drawing with NSLayoutManager?

≡放荡痞女 提交于 2019-12-19 08:28:11
问题 My ultimate goal is to give the user the ability to split a text inside an NSTextView or UITextView into several sections , where two subsequent sections are visually separated by a custom view separator (possibly, but not necessarily a horizontal rule – I want to be able to adjust the visual appearance of the separator without a hassle). I need a solution that works on both platforms: macOS and iOS . (My related question focused on a solution for macOS and there is one that makes use of

Modifying NSTextStorage causes insertion point to move to the end of the line

无人久伴 提交于 2019-12-19 05:24:54
问题 I've got an NSTextView subclass acting as its NSTextStorage delegate. I'm trying to do 2 things: Highlight the text in some ways Evaluate the text and then append the answer to the textview. I'm doing this in two different methods, both invoked by the - (void)textStorageWillProcessEditing:(NSNotification *)notification delegate callback. I can do the syntax highlighting just fine, but when it comes to appending my answer, the insertion point jumps to the end of the line and I don't really

Crashing on range on NSTextStorage

只愿长相守 提交于 2019-12-12 16:04:14
问题 I have a UITextView that should receive NSAttributesString contracted from HTML. The end result is black text with custom underline for links. I am crashing on range. Terminating app due to uncaught exception 'NSRangeException', reason: 'NSMutableRLEArray objectAtIndex:effectiveRange:: Out of bounds' Here is the code: import UIKit class ViewController: UIViewController { override func viewDidLoad() { super.viewDidLoad() let text = "random text <a href='http://www.google.com'>http://www.google

Which replacement method is called when editing an attributed string?

核能气质少年 提交于 2019-12-11 05:29:22
问题 NSMutableAttributedString defines two string replacement methods: func replaceCharacters(in range: NSRange, with str: String) and func replaceCharacters(in range: NSRange, with attrString: NSAttributedString) I have created a subclass of NSTextStorage which in its turn is a subclass of NSMutableAttributedString . In that subclass I overrode both of the above methods. To my surprise, the latter method (which passes an attributed replacement string) is never called when I type or paste

iOS文本布局探讨之一——文本布局框架TextKit浅析

北战南征 提交于 2019-12-10 13:38:11
iOS文本布局探讨之一——文本布局框架TextKit浅析 一、引言 在iOS开发中,处理文本的视图控件主要有4中,UILabel,UITextField,UITextView和UIWebView。其中UILabel与UITextField相对简单,UITextView是功能完备的文本布局展示类,通过它可以进行复杂的富文本布局,UIWebView主要用来加载网页或者pdf文件,其可以进行HTML,CSS和JS等文件的解析。 TextKit是一个偏上层的开发框架,在iOS7以上可用,使用它开发者可以方便灵活处理复杂的文本布局,满足开发中对文本布局的各种复杂需求。TextKit实际上是基于CoreText的一个上层框架,其是面向对象的,如果TextKit中提供的API无法满足需求,可以使用CoreText中的API进行更底层的开发。 官方文档中的一张图片很确切,经常会被用来描述TextKit框架在iOS系统文本渲染中所处的位置。 二、TextKit框架的结构 界面在进行文本的渲染时,有下面几个必要条件: 1.要渲染展示的内容。 2.将内容渲染在某个视图上。 3.内容渲染在视图上的尺寸位置和形状。 在TextKit框架中,提供了几个类分别对应处理上述的必要条件: 1.NSTextStorage对应要渲染展示的内容。 2.UITextView对应要渲染的视图。 3

UITextView crash in iOS 8 with attributed string containing a table

对着背影说爱祢 提交于 2019-12-07 00:36:04
问题 In iOS 8 (or possibly even in iOS 7/7.1) NSAttributedString on iOS added the ability to render text tables. This API is public on OS X but not on iOS. However, it is possible to create an attributed string containing a text table on iOS by passing HTML containing a table to -[NSAttributedString initWithData:options:documentAttributes:error:]. The attributed string is created correctly, but when I attempt to render the string using a UITextView , this exception gets thrown: <NSATSTypesetter:

UITextView crash in iOS 8 with attributed string containing a table

纵然是瞬间 提交于 2019-12-05 04:08:47
In iOS 8 (or possibly even in iOS 7/7.1) NSAttributedString on iOS added the ability to render text tables. This API is public on OS X but not on iOS. However, it is possible to create an attributed string containing a text table on iOS by passing HTML containing a table to -[NSAttributedString initWithData:options:documentAttributes:error:] . The attributed string is created correctly, but when I attempt to render the string using a UITextView , this exception gets thrown: <NSATSTypesetter: 0x7f8900faec90>: Exception *** -[NSConcreteTextStorage attribute:atIndex:effectiveRange:]: Range or

How to extend NSTextStorage?

浪子不回头ぞ 提交于 2019-12-05 01:44:13
According to documentation, I try to subclass NSTextStorage and use it in text view: /* NSTextStorage is a semi-abstract subclass of NSMutableAttributedString. It implements change management (beginEditing/endEditing), verification of attributes, delegate handling, and layout management notification. The one aspect it does not implement is the actual attributed string storage --- this is left up to the subclassers, which need to override the two NSMutableAttributedString primitives: - (void)replaceCharactersInRange:(NSRange)range withString:(NSString *)str; - (void)setAttributes:(NSDictionary

Proper way to replace NSTextStorage in NSTextView?

家住魔仙堡 提交于 2019-12-04 18:56:54
问题 I am making some text viewer app. Currently I need very frequent and precise line handling ability, so I want to subclass NSTextStorage class. But I couldn't find any method to set a new text storage to NSTextView . The only method I could find was -[NSLayoutManager replaceTextStorage:] method. But it's confusing whether this is what I was looking for. Because it seems just replace text storage of linked NSLayoutManagers instead of NSTextView. I also considered subclassing NSTextView and

Sub-Classing NSTextStorage Causes Significant Memory Issues

廉价感情. 提交于 2019-12-04 13:17:39
问题 I have a custom UITextView that takes advantage of Apple's TextKit by defining a custom NSTextStorage class, however, when I use my subclass for the custom text view's, text storage (as implemented below) and try opening any file greater than 20.0KB, the app crashes due to memory leakage: " Message from debugger: Terminated due to memory issue ". Oddly enough, if I replace my custom BMTextStorage with just a standard one, NSTextStorage , the text loads instantly without any memory leakage and