nslayoutmanager

NSLayoutManager with multiple NSTextContainers causes UITextViews to not be selectable/editable

笑着哭i 提交于 2020-05-10 20:55:56
问题 I am trying to achieve a multi page text editing layout, as in Pages, MS Word, ... . On OS X I can achieve this by creating one NSLayoutManager with one NSTextStorage for multiple NSTextViews. Each NSTextView has its own NSTextContainer. See below code for OS X. A simple example with text spreading between two NSTextViews: import Cocoa class ViewController: NSViewController { let layoutManager = NSLayoutManager() let textStorage = NSTextStorage(attributedString: NSAttributedString(string:

NSLayoutManager with multiple NSTextContainers causes UITextViews to not be selectable/editable

不打扰是莪最后的温柔 提交于 2020-05-10 20:55:48
问题 I am trying to achieve a multi page text editing layout, as in Pages, MS Word, ... . On OS X I can achieve this by creating one NSLayoutManager with one NSTextStorage for multiple NSTextViews. Each NSTextView has its own NSTextContainer. See below code for OS X. A simple example with text spreading between two NSTextViews: import Cocoa class ViewController: NSViewController { let layoutManager = NSLayoutManager() let textStorage = NSTextStorage(attributedString: NSAttributedString(string:

replace layout manager of uitextview

时光毁灭记忆、已成空白 提交于 2020-02-15 08:23:12
问题 NSTextContainer on Mac OS X has a method replaceLayoutManager: to replace the NSLayoutManager of NSTextView with a subclass of NSLayoutManager. Unfortunately iOS doesn't have such a function. I tried a combination of these lines of code, but it keeps crashing. THLayoutManager *layoutManager = [[THLayoutManager alloc] init]; [layoutManager addTextContainer:[self textContainer]]; // [[self textStorage] removeLayoutManager:[self layoutManager]]; //[[self textStorage] addLayoutManager

Using NSGlyph and memory allocation

こ雲淡風輕ζ 提交于 2019-12-31 04:49:05
问题 in a method to track line breaks frequently , for a NSTextView visibleRect , i am allocating memory for NSGlyph to use NSLayoutManager getGlyphs:range: . should/can i find out how much memory this should be since i have a reference for the range (without affecting layout), and also, what kind of cleanup should happen -- running with ARC ? the code (which runs on a main queue) : NSLayoutManager *lm = [self.textView layoutManager]; NSTextContainer *tc = [self.textView textContainer]; NSRect

iOS7 Type into UITextView with Line Spacing and keep formatting using TextKit

十年热恋 提交于 2019-12-25 03:18:29
问题 I came across this great example which helped me understand how I can achieve line spacing / paragraph spacing as you type inside a UITextView with iOS7, however there is a problem and I am hoping someone can help me with resolving an issue as I am still learning about TextKit please. This is the actual example https://github.com/downie/DoubleSpacedTextView I have attached 2 files:- 1- This is a video of the problem:- http://1drv.ms/1o8Rpd2 2- This is the project I am testing with: http:/

NSLayoutManager: Calling setLocation(_:forStartOfGlyphRange:) disables kerning in the whole string?

折月煮酒 提交于 2019-12-21 23:18:13
问题 I created simple NSLayoutManager subclass that allows to set custom layout location for defined substrings: class PositionableLayoutManager: NSLayoutManager { var xOffsetsPerGlyphRange = [(NSRange, CGPoint)]() override func invalidateLayoutForCharacterRange(charRange: NSRange, actualCharacterRange actualCharRange: NSRangePointer) { super.invalidateLayoutForCharacterRange(charRange, actualCharacterRange: actualCharRange) for (range, offset) in xOffsetsPerGlyphRange { setLocation(offset,

In my programmatically instantiated UITextView (initialized with NSTextContainer) the .text property is always nil

試著忘記壹切 提交于 2019-12-21 06:15:05
问题 [UPDATED w/ SOLUTION and WORKING CODE in bottom section] In -viewDidLoad I alloc, initWithFrame: Add myTextView to subView Set some basic properties (alignment, background color, text color, etc) Set default text The .text does not appear. myTextView appears (as indicated by background color), set breakpoint, it has a frame, memory, etc. Everything looks right. myTextView looks good, but the .text is nil. I change it, set it, update it. No matter what the .text remains nil. I have read the

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

How does line spacing work in Core Text? (and why is it different from NSLayoutManager?)

会有一股神秘感。 提交于 2019-12-17 17:25:14
问题 I'm trying to draw text using Core Text functions, with a line spacing that's as close as possible to what it would be if I used NSTextView. Take this font as an example: NSFont *font = [NSFont fontWithName:@"Times New Roman" size:96.0]; The line height of this font, if I would use it in an NSTextView is 111.0. NSLayoutManager *lm = [[NSLayoutManager alloc] init]; NSLog(@"%f", [lm defaultLineHeightForFont:font]); // this is 111.0 Now, if I do the same thing with Core Text, the result is 110.4

Using NSLayoutManager to calculate frames for each glyph

℡╲_俬逩灬. 提交于 2019-12-12 07:44:49
问题 On this thread, Core Text calculate letter frame in iOS, they were able to calculate the frame of each glyph very precisely using Core Text. The final rects hug the actual drawn glyphs perfectly. Using NSLayoutManager's boundingRectForGlyphRange:inTextContainer: doesn't seem to return the glyph bounding boxes that precisely: And the returned rects don't fully enclose more complex fonts (Zapfino example): Does anyone know how to replicate the results from the above mentioned discussion without