Questions tagged [textkit]

Text Kit is, collectively, a set of classes and protocols in iOS 7's UIKit framework that provide high-quality typographical services.

Text Kit, introduced in iOS 7, is a set of classes and protocols providing high quality typographical services including text layout, storage and display. It also enables direct control of typographical features such as kerning, ligatures, line break behaviour and justification. Text-related UIKit classes in iOS 7 - namely UITextView, UITextField and UILabel - are based on the Text Kit layout engine.

Allowing fine-grained control of fonts and styles through a mechanism Apple calls "Dynamic Type", Text Kit brings a much more refined an detailed system for text-handling to iOS.

272 questions
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
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
1 answer

NSLayoutManager boundingRectForGlyphRange off by some Points

I want to "highlight" specific words in UITextView, not with a solid color (which would be possible via NSAttributedString), but rather with a gradient and maybe some other fancy effects. Hence, I decided it would be necessary to manually create a…
Luis Nell
  • 534
  • 4
  • 12
6
votes
1 answer

Subclass of NSTextStorage causes crash on access link

I'm building a custom NSTextStorage class to find&match custom user input and process it inside my app. So I followed a couple of tutorials, most notably objc.io's, and created a subclass and set it's layoutManager to the same of the UITextView…
Pierluigi Cifani
  • 224
  • 2
  • 14
6
votes
1 answer

([NSAttributedString boundingRectWithSize:options:context:])method can not get the right size within NSTextAttachment

in my codes: NSMutableAttributedString *str = [[NSMutableAttributedString alloc] initWithString:@"12123"]; NSTextAttachment *attachment = [[NSTextAttachment alloc] init]; attachment.image = [UIImage imageNamed:@"002"]; attachment.bounds =…
Eric Chen
  • 103
  • 1
  • 4
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
6
votes
4 answers

NSAttributedString changed font unexpectedly after inserting Image

I am using Text Kit in iOS 7 to create a rich text editor. Following is the problem. At first, then font size is 16: Then I insert an image using the code: // Image Attachment NSTextAttachment *imageAttachment = [[NSTextAttachment alloc]…
HanXu
  • 5,507
  • 6
  • 52
  • 76
6
votes
1 answer

How to Center Text Vertically in a UITextView using Text Kit (iOS 7)

Summary: In iOS 6, I centered text vertically in a UITextView by key-value-observing the text view's contentSize property (https://stackoverflow.com/a/12591299/1239263). When I upgraded to iOS 7, the latter technique worked inconsistently. Rather…
bilobatum
  • 8,918
  • 6
  • 36
  • 50
5
votes
1 answer

TextKit 2 - How to create word level NSTextElements in order to tag words in text

I'm trying to create tags/labels/badges to tag certain words(actually sometimes multiple words can constitute a tag). Currently, I've added a custom NSAttributedString key that I have used to tag words with their part of speech. I want to tag these…
Peter R
  • 3,185
  • 23
  • 43
5
votes
1 answer

Inline button and/or textfield within string which wraps the same as text using Swift

This is more of a question of how to go about achieving it rather than a specific solution. I would like to have a label which allowed buttons and textfields to be inline and wrap to the next line. An example is the iOS shortcuts app where you can…
Andrew Harris
  • 396
  • 7
  • 24
5
votes
1 answer

iOS Hyphenation with TextKit and justified text

Good day everyone. I have a problem with displaying hyphenated justified text using TextKit with a textview. I've tried to make hyphenation through paragraph style and NSLayoutManager, but without expected results. Paragraph style example: let…
Igor Prusyazhnyuk
  • 133
  • 2
  • 14
  • 29
5
votes
0 answers

Text folding in NSTextView / UITextView using Text Kit

At WWDC 2013 it was noted a few times that Text Kit would simplify advanced techniques like text folding. But no sample code was offered for that particular session (220), and repeated searches on how to do this have been mostly unfruitful. What I'd…
Ryan Jones
  • 79
  • 6
5
votes
1 answer

Sub-Classing NSTextStorage Causes Significant Memory Issues

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…
rolling_codes
  • 15,174
  • 22
  • 76
  • 112
5
votes
1 answer

put UILabel/UITextField on next line instead of pushing out of view

I'm creating a natural language form and whenever the user enters an input which is quite large, I want the entire line to move to the next line (just like an UITextView). Right now, I get this result: This indicates two obvious problems: for one:…
bdv
  • 1,154
  • 2
  • 19
  • 42