Questions tagged [nslayoutmanager]

Glyph layout engine in iOS and OSX

Responsible for converting characters drawn from NSTextStorage and laying them out as glyphs following the display/geometric constraints provided by one or more NSTextContainer.

120 questions
9
votes
1 answer

Scrolling Performance issue with UItextView with large NSAttributedString

I am working on text editor for an app. I am using UITextView See the sample code to load text view. // Read text from file (around 300k - 400k words) NSError *error = nil; NSString *contentOfFile = [[NSString alloc]…
9
votes
1 answer

Using a CALayer to highlight text in a UITextView which spans multiple lines

This is a continuation of Getting CGRect for text in a UITextView for the purpose of highlighting with a CALayer. I'm having trouble with getting the correct rectangle for the ranges in each line fragment. NSString* searchString = @"Returns the…
Myron Slaw
  • 886
  • 9
  • 21
9
votes
3 answers

UITextView contentSize changes and NSLayoutManager in iOS7

The problem: UITextView silently changes it's contentSize in some situations. The simplest case textView with large text and keyboard. Just add UITextView outlet and set - viewDidLoad as: - (void)viewDidLoad { [super viewDidLoad]; // expand…
zxcat
  • 2,054
  • 3
  • 26
  • 40
7
votes
2 answers

Getting a glyph boundingRect in draw#rect in UILabel

Using Swift, I want to get the boundingRect of a glyph, in draw#rect in a UILabel. The UILabel already has a size (say 300x300 in the example) and qualities such as the text being centered. class RNDLabel: UILabel { override func draw(_ rect:…
Fattie
  • 27,874
  • 70
  • 431
  • 719
7
votes
1 answer

How to define a custom NSUnderlineStyle

Looking at the documentation for NSLayoutManager, specifically the drawUnderlineForGlyphRange:underlineType:baselineOffset:lineFragmentRect:lineFragmentGlyphRange:containerOrigin: method, I noticed the following (emphasis mine): underlineVal The…
Arnold
  • 2,390
  • 1
  • 26
  • 45
7
votes
0 answers

How to replace the text storage of an NSLayoutManager

I'm trying to build a table view cell that has a UITextView. To reuse this table view cell, I set a new text storage to the layout manager. But adding the layout manager to the new text storage does not change the text storage of the text view. The…
Tobias Kräntzer
  • 1,694
  • 1
  • 13
  • 23
7
votes
2 answers

iOS 7 UITextView: Size of nstextattachment getting 2x after reopening the application

I am building a note editor using the Text Kit in ios7. Earlier I had trouble in rendering of custom size NSTextAttachment's as it was slowing down the rendering to a great extent.I solved the issue by scaling the images and then adding them to…
nick28
  • 134
  • 2
  • 7
7
votes
1 answer

Invalid glyph index when setting viewController's layoutManager for NSTextStorage subclass

My goal is to use TextKit to italicize, set the text size, etc. of certain words. To start, I am only trying to highlight a character in my text string. Being new to TextKit (and truthfully to programming in general), I am following the syntax…
Jeff Lewis
  • 135
  • 4
  • 11
7
votes
1 answer

Saving and restoring NSTextView's position

I want to be able to save the current text and visible region of an NSTextView and restore it. Using visibleRect and scrollRectToVisible: seems to deliver inconsistent results. If I just do: - (void)restorePosition { NSRect r = [self.textView…
Matt
  • 385
  • 3
  • 8
7
votes
2 answers

Sequential selection among multiple NSTextViews

I have a bunch of NSTextViews that I would like to share a single selection. I basically want this to behave like selecting text on a web page, where there are multiple text views but you can drag to sequentially select text among them. I found this…
indragie
  • 18,002
  • 16
  • 95
  • 164
6
votes
2 answers

NSLayoutManager: How to fill background colors where there are renderable glyphs only

The default layout manager fills in the background color (specified via NSAttributedString .backgroundColor attribute) where there's no text (except for the last line). I've managed to achieve the effect I want by sublclassing NSLayoutManager and…
Aodh
  • 662
  • 1
  • 7
  • 24
6
votes
0 answers

NSTextStorage easily / background attribute change

I'm finishing a nice app with a relatively small text editor. During implementation of the syntax highlight I found myself in need to change foreground colour attribute of recognized tokens. I noticed that there is a property of NSTextStorage: var…
Ivaylo Nikolov
  • 501
  • 4
  • 13
6
votes
1 answer

Can NSLayoutManager be safely used on background thread?

Even though the iOS doc says: NLayoutManager, NSTextStorage, and NSTextContainer can be accessed from subthreads as long as the app guarantees the access from a single thread. I encountered this exception occasionally: Terminating app due to…
an0
  • 17,191
  • 12
  • 86
  • 136
5
votes
0 answers

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

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…
Mischa
  • 15,816
  • 8
  • 59
  • 117
5
votes
2 answers

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

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…