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
0
votes
1 answer

How to fix iOS custom shaped text layout incorrect ellipse behavior?

I am learning iOS textkit from official tutorials here: https://developer.apple.com/documentation/uikit/textkit/display_text_with_a_custom_layout After running and testing the code for a while, I found an incorrect ellipse beahavior: The code uses…
laishere
  • 95
  • 7
0
votes
0 answers

Save NSAttributedString as rtfd in iOS

I'm trying to implement a text editor in iOS. It supports basic styles and is able to embed an image. For testing, I created a .rtfd file in Xcode like this: Here is part of my code: // Create a text storage object and add it to the layout…
Bagusflyer
  • 12,675
  • 21
  • 96
  • 179
0
votes
0 answers

Setting text alignment when using custom UITextContainer

We are currently using a standard UITextView and setting the text to be displayed using the text property. We have overridden the text property as below to find out whether the text should be left or right aligned. override public var text: String!…
förschter
  • 740
  • 1
  • 7
  • 24
0
votes
1 answer

Replacing layout manager in UITextView using TextKit 1

I have a UITextView created in storyboard. The view uses TextKit 1, and I'm trying to replace the NSLayoutManager. When calling .sizeThatFits() (or any other method requiring layout) on my text view, I'm getting an uncaught exception: ***…
Tritonal
  • 607
  • 4
  • 16
0
votes
0 answers

Using TextKit 2 to display tables in UITextView

UITextView does not support any kind of tables, but I'm trying to create a text view implementation which would be able to show tables alongside normal text. Basically: My macOS port uses NSTextTable to render some paragraphs next to each other when…
Tritonal
  • 607
  • 4
  • 16
0
votes
0 answers

Force page breaks and text containers using NSLayoutManager

I'm trying to implement pagination using NSLayoutManager and multiple text containers. Creating NSTextView/UITextView instances works as expected, and the text flows from text view to another. However, I'd like to force a page break, ie. determine…
Tritonal
  • 607
  • 4
  • 16
0
votes
0 answers

What is the difference between `lineFragmentRect` and `lineFragmentUsedRect`?

What is the difference between NSLayoutManager.lineFragmentRect and NSLayoutManager.lineFragmentUsedRect?
iMoeNya
  • 672
  • 4
  • 11
0
votes
0 answers

Remove markdown characters with Textkit?

I'm trying to build a markdown editor in macOS and I found this package: https://github.com/kyle-n/HighlightedTextEditor However, the one thing I would like to extend is the possibility to have markdown characters removed. E.g when typng **bold**,…
erikvm
  • 858
  • 10
  • 30
0
votes
0 answers

TextKit 1 in Labels as default in iOS 16

Due to the iOS 16 will be using TextKit 2 as default, does anyone know if it is possible to set TextKit 1 as default in the UILabels in iOS 16? We need to keep the same UI in iOS 16 and iOS 15 by contract (the app only supports iPhone 11 pro) and we…
Luciano Perez
  • 101
  • 1
  • 10
0
votes
1 answer

NSAttributedString change font size

I have an NSAttributedString which may have multiple subranges with different font styles and other attributes. How do I modify the size of font for the whole attributed string? Setting a font size of 20 should set pointSize of all fonts in the…
0
votes
0 answers

NSMutableRLEArray objectAtIndex:effectiveRange:: Out of bounds Error

I 'm trying to add attributes to a certain range of characters in textView on basis of break line character.The app is crashing and throwing out of bound error.Not sure why because the range to which I'm applying attributes is within the text…
NewUser
  • 21
  • 3
0
votes
0 answers

How to get the range and Cursor Position in UITextView

Hello I'm trying to create a custom text editor, for which I want to know the position of the cursor and range of the text in UITextView for which I can apply TextAttributes based on the user selected options. For eg: \n This is a the first…
NewUser
  • 21
  • 3
0
votes
0 answers

Removing custom attributes in NSTextView before drawing

In TextKit Best Practices WWDC lecture, it is mentioned that custom attributes can slow down NSTextView drawing, and recommends stripping those attributes before sending the string for rendering. I'm using custom attributes which contain tagging…
Tritonal
  • 607
  • 4
  • 16
0
votes
1 answer

CTFontGetGlyphsForCharacters Returns false when passing emoji

In a class conforming to NSLayoutManagerDelegate I implement this method: func layoutManager(_ layoutManager: NSLayoutManager, shouldGenerateGlyphs glyphs: UnsafePointer, properties props:…
WikipediaBrown
  • 689
  • 1
  • 8
  • 27
0
votes
1 answer

How to encode images with text as attributed strings

I am inserting images into a TextKit textView using an NSMutableAttributed string and NSAttachment with the following Swift imagePickerController code: func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info:…
user46938
  • 59
  • 4