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
3
votes
2 answers

How to properly determine width of an attributed string

What I want to do: layout text using NSLayoutManager and set its NSTextContainer to the width of the widest string (glyph-wise) in an array of strings. What my problem is: The methods for determining the total 'glyph-width' seem to be incorrect…
3
votes
1 answer

Clarifying the behaviour of NSLayoutManager & NSTextContainer with respect to vertical layout?

Code Sample I have a NSLayoutManager, NSTextContainer & NSTextStorage as properties in a custom NSView (not a TextView) initialized in awakeFromNib() as follows: textStorage = NSTextStorage(attributedString: self.attributedString) …
Sam
  • 2,745
  • 3
  • 20
  • 42
3
votes
1 answer

get text in NSTextContainer

I have a NSOrderedSet of paragraphs with NSString content. Looping through all, a large string is created and given NSTextStorage. But with that all the paragraphs are lost. The code below allows me to count the pages and present the content in…
Giwan
  • 1,564
  • 14
  • 17
3
votes
1 answer

Computing text size with NSLayoutManager

I'm working on a view which uses TextKit framework to typeset text in columns like this: I use my UIView's bounds with edge insets (black rectangle) to compute 10 CGRects which I then transform into NSTextContainers (red rectangles). In drawRect: I…
Petr Mánek
  • 1,046
  • 1
  • 9
  • 24
3
votes
1 answer

'-[UITextView autocapitalizationType]: unrecognized selector sent to instance?

I would like to create custom subclasses(SubCustomView) of uiview when click on button and added uitextview class on SubCustomView as subview. when i initiate uitextview i use initWithFrame:textContainer: method. when i used this method, the project…
Prasad G
  • 6,702
  • 7
  • 42
  • 65
2
votes
1 answer

Scrollable NSTextView with custom NSTextStorage for formatting

I'm trying to make a text editor with formatting for Mac OS. Which I have working using an NSTextView together with a custom NSTextStorage class. Which applies attributes like bold etc to NSAttributableStrings. This all seems to work fine as seen in…
Matthijn
  • 3,126
  • 9
  • 46
  • 69
2
votes
1 answer

NSLayoutManager Text new line seems to start from bottom of rectangle and go up

m_LayoutManager = [[NSLayoutManager alloc] init]; m_TextContainer = [[NSTextContainer alloc] init]; m_TextStorage = [[NSTextStorage alloc] initWithString: @"Here's to the crazy ones, the misfits, the rebels, the troublemakers, the round pegs in the…
user805547
  • 1,245
  • 1
  • 15
  • 23
2
votes
2 answers

NSTextView lineHeightMultiple drawing issues

By setting the lineHeightMultiple of a NSParagraphStyle that is used in a text view I'm getting drawing artifacts when selecting text. This is reproducible in TextEdit. More specifically: Open TextEdit in rich text mode Pick Courier 14 as the…
user139992
2
votes
0 answers

How to get height of string with maximum lines using NSTextStorage?

I am trying to get the height of an attributed string (for any font, any language, any strange utf8 characters, etc). I found this interesting topic at Badoo Chatto about different solutions: https://github.com/badoo/Chatto/issues/129 And the…
Kalzem
  • 7,320
  • 6
  • 54
  • 79
2
votes
0 answers

TextKit - UILabel with background and spacing

I've been working on something like this. Everything was working fine until I've found out a string input that causes an issue The input string is "This is a long titlessss \n Withssssssss" Basically, it seems like the "long" word fits the space…
ndPPPhz
  • 315
  • 1
  • 15
2
votes
0 answers

Receive immediate layout updates from NSLayoutManager

I'm currently setting a delegate on the layout manager and reacting to layoutManager(_:didCompleteLayoutFor:atEnd:), but there seems to be a slight delay between the layout being updated visually (by editing the text or resizing the NSTextView) and…
T .
  • 4,874
  • 3
  • 23
  • 36
2
votes
0 answers

Calculate glyph run bounds with NSLayoutManager

I'm trying to achieve a visual effect with a UITextView whereby the text has a distinct background color, eg: The approach I tried to build on was based on a code snippet from Apple used to calculate lines, and then built upon as shown in this…
isaac
  • 4,867
  • 1
  • 21
  • 31
2
votes
1 answer

NSStackView places NSViews on the baseline

Having reviewed most of Apple's (paucity) of documentation regarding NSStackView, plus the wise words of the greater Internet, including the collective wisdom of Stackoverflow, a problem remains. Any NSView I add programmatically to my (IB…
2
votes
1 answer

enumerateLineFragmentsForGlyphRange:withBlock: returns word fragments

I'm using a UITextView to display some text. In laying out the text, I enumerate the lines of text using the enumerateLineFragmentsForGlyphRange:withBlock: method. NSInteger shrunkNumberOfLines = 3; __block NSMutableString *shortenedText =…
bryanjclark
  • 6,247
  • 2
  • 35
  • 68
2
votes
2 answers

Adding Multiple NSTextContainers to an NSLayoutManager

I notice that you can add multiple text containers to a layout manager in Objective-C using the addTextContainer:(NSTextContainer *)textContainer selector. Using TextKit, I've only ever had to add one text container, and when messing around with…