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

Get index of character in UILabel from tap

I'd like to get the index for the tapped character on a UILabel. I've subclassed a UILabel. In my awakeFromNib() I have this: layoutManager = NSLayoutManager() textStorage = NSTextStorage(attributedString: self.attributedText) …
SirRupertIII
  • 12,324
  • 20
  • 72
  • 121
5
votes
2 answers

What is Causing this Unwanted Content Inset with UITextView in iOS 8 (not there in iOS 7)?

I've been creating UITextViews programatically, using auto layout, in iOS 7. Something like this: _textView = [UITextView new]; _textView.translatesAutoresizingMaskIntoConstraints = NO; _textView.font = [UIFont…
Gavin Hope
  • 2,173
  • 24
  • 38
4
votes
1 answer

NSLayoutManager setAllowsNonContiguousLayout misplaces caret

With setAllowsNonContiguousLayout set to YES, if I perform the following steps I get weird behaviour: Select all text in the NSTextView Hit backspace to remove all the text Type a few lines of text Trying using backspace to delete the text…
d11wtq
  • 34,788
  • 19
  • 120
  • 195
4
votes
2 answers

NSLayoutManager hides new line characters no matter what I do

I'm trying to show invisible characters like the new line character in my NSTextView subclass. The usual approach like overriding drawGlyph method of NSLayoutManager is a bad idea because it's too slow and not work properly with multi-paged…
Vitalii Vashchenko
  • 1,777
  • 1
  • 13
  • 23
4
votes
0 answers

Retrieving accurate layout information from UITextView

I am trying to position a UIButton in a UITextView at a specific point in a large block of dynamically-generated text. However, it is proving devilishly difficult to get accurate coordinates in a timely fashion. The attributedText has been set with…
Andy Shamel
  • 151
  • 1
  • 6
4
votes
1 answer

NSLayoutManager, boundingRectForGlyphRange and emoji

I am displaying text that may contain emoji using NSAttributedString's drawInRect(rect: CGRect) method. Since I want to detect taps on the text I use the following method to see which character has been tapped: let textStorage =…
Gert-Jan
  • 51
  • 4
4
votes
2 answers

Why do I fail to get textContainer's rect by using "usedRectForTextContainer"

I learned the answer by NAlexN in this Question (Create tap-able "links" in the NSAttributedString of a UILabel?), and write a demo by myself. However, it is unluck for me to work the demo out. Here is my code: (everyone can copy following code to a…
4
votes
2 answers

replace layout manager of uitextview

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…
user965972
  • 2,489
  • 2
  • 23
  • 39
4
votes
3 answers

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

[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.…
3
votes
1 answer

How to get the range of characters that are visible from within -textStorageDidProcessEditing:?

For my syntax highlighting implementation, I observe changes to an NSTextView using -[ textStorageDidProcessEditing:]. - (void)textStorageDidProcessEditing:(NSNotification *)notification { if (!self.languageGrammar) return; …
user142019
3
votes
1 answer

How can I replicate GitHub's app code block style in UITextView?

I am trying to create a markdown editor for fun and because I was interested in learning TextKit. I am working on iOS devices only, so I only have UIKit framework at my disposal, also I watched this WWDC18 video which explains some best practices to…
3
votes
1 answer

Locate character coordinate in Custom UILabel with attributedText

i need to locate my character location in my UILabel (it has ParagraphLineSpacing and AttributedText with multiline), i have got my character's index, but now i can't get X and Y coordinate from my index. i Have found this…
calvin sugianto
  • 610
  • 7
  • 27
3
votes
0 answers

Is there any way I can get precise metrics (line ascent, line descent, etc.) of the lines in a NSLayoutManager?

This is a followup to this. After encountering issues with certain character compositions not working identically between Cocoa and Core Text, I decided to give Cocoa's text API a chance. Now, I need to be able to decompose a line vertically into…
andlabs
  • 11,290
  • 1
  • 31
  • 52
3
votes
1 answer

Force NSLayoutManager to draw a glyph with a different font

I'm trying to force NSLayoutManager to draw a glyph at some range with different attributes but it still uses the attributes set in the NSTextStorage. I was trying to create NSGlyph from different font and replace it with the one in NSTypesetter's…
Vitalii Vashchenko
  • 1,777
  • 1
  • 13
  • 23
3
votes
0 answers

How to properly draw underlines in NSLayoutManager

I have currently subclassed NSLayoutManager along with other classes in the UITextView architecture in order to implement my own Word Processor like UITextView. I am currently facing a problem when trying to layout underlines under ranges of glyphs…
AyBayBay
  • 1,726
  • 4
  • 18
  • 37