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
189
votes
21 answers

How to embed small icon in UILabel

I need to embed small icons ( sort of custom bullets ) to my UILabel in iOS7. How can I do this in interface designer? Or at least in code? In Android there are leftDrawable and rightDrawable for labels, but how it is done in iOS? Sample in android…
AVEbrahimi
  • 17,993
  • 23
  • 107
  • 210
129
votes
12 answers

Detecting taps on attributed text in a UITextView in iOS

I have a UITextView which displays an NSAttributedString. This string contains words that I'd like to make tappable, such that when they are tapped I get called back so that I can perform an action. I realise that UITextView can detect taps on a URL…
tarmes
  • 15,366
  • 10
  • 53
  • 87
111
votes
5 answers

iOS 7 TextKit - How to insert images inline with text?

I am trying to get the following effect using a UITextView: Basically I want to insert an image between text. The image can simply just take up 1 row of space so there is no wrapping necessary. I tried just adding a UIView to the subview: UIView…
Andy Hin
  • 30,345
  • 42
  • 99
  • 142
81
votes
9 answers

How do I locate the CGRect for a substring of text in a UILabel?

For a given NSRange, I'd like to find a CGRect in a UILabel that corresponds to the glyphs of that NSRange. For example, I'd like to find the CGRect that contains the word "dog" in the sentence "The quick brown fox jumps over the lazy dog." The…
bryanjclark
  • 6,247
  • 2
  • 35
  • 68
39
votes
3 answers

Adjust letter spacing in iOS 7

In iOS 7, when navigating back using the new swipe-from-edge-of-screen gesture, the title of the Back button ("Artists") fades from being pink (in the example below) and having regular font weight to being black and having bold font weight. It…
wstr
  • 910
  • 2
  • 13
  • 23
34
votes
1 answer

How can I set the color and alignment of attributed text in a UITextView in iOS 7?

The formatting of my textViews worked fine in iOS 6, but no longer in iOS 7. I understand with Text Kit much of the under the hood stuff has changed. It's become really quite confusing, and I'm hoping someone can help straighten it out a bit by…
Joe
  • 854
  • 3
  • 11
  • 21
26
votes
9 answers

Character index at touch point for UILabel

For a UILabel, I'd like to find out which character index is at specific point received from a touch event. I'd like to solve this problem for iOS 7 using Text Kit. Since UILabel doesn't provide access to its NSLayoutManager, I created my own based…
Claus
  • 331
  • 1
  • 3
  • 7
24
votes
3 answers

iOS NSAttributedString to HTML

I have an NSAttributed string (coming from HTML) that I set for a UITextView. - (void)setHtml:(NSString *)html { NSData *htmlData = [html dataUsingEncoding:NSUTF8StringEncoding]; // Create the HTML string NSDictionary *importParams =…
Nic Hubbard
  • 41,587
  • 63
  • 251
  • 412
20
votes
1 answer

How to set heading, subheading, body, footnote, and captions font for dynamic type text styles in Swift?

I was working through the Using Text Kit to Manage Text in Your iOS Apps tutorial. It was written for Objective C but I thought I would try to do it anyway using Swift. However, when I got to the following code I couldn't figure out how to set the…
Suragch
  • 484,302
  • 314
  • 1,365
  • 1,393
20
votes
8 answers

iOS7 TextKit: bullet point alignment

I'm writing an app for iOS 7 only and I'm trying to get decent formatting on bullet points in a non-editable UITextView. It's easy enough to just insert a bullet point character, but of course the left indentation won't follow. What's the easiest…
Frank R.
  • 2,328
  • 1
  • 24
  • 44
20
votes
4 answers

Lines missing from tall UILabel when embedding NSTextAttachment

I can create a multi-line NSAttributedString by using escaped new-line characters (@"\n"). With iOS 7, I can now embed a UIImage inside attributed strings (via NSTextAttachment). I have noticed that whenever I set the attributedText of a UILabel to…
oo-di-lolly
  • 213
  • 3
  • 6
18
votes
3 answers

How to wrap text around attachments using iOS7 Text Kit?

I am using the new Text Kit API to add attachments to some attributed text: // create an attachment for each image NSTextAttachment* ta = [NSTextAttachment new]; ta.image = [UIImage imageNamed:@"imageName"]; // add to the attributed text…
ColinE
  • 68,894
  • 15
  • 164
  • 232
17
votes
1 answer

Animated UIImage in UITextView with TextKit

I have a UIImage that contains multiple image frames and a duration which was sliced together from an animated GIF file. If I load the image in a UIWebView it will animate as expected, but I want to use a UITextView instead. The obvious choice is to…
afrederick
  • 1,388
  • 1
  • 10
  • 24
16
votes
1 answer

UITextView – can't set underline or strikethrough attributes on text?

I'm getting runtime failures whenever I try to set underline or strikethrough attributes on the attributedText of a UITextView. Other properties, like font and background color have no problems. Here's a code snippet. All I have is a test project…
Adam Bryant
  • 545
  • 3
  • 13
16
votes
1 answer

Creating a text editor for iOS 7

Problem I need to understand how TextKit works and how I can use it to build a text editor. I need to figure out how to draw ONLY the visible text the end-user interacts with or determine how I would go about lazily applying attributes to the…
PeqNP
  • 1,363
  • 15
  • 26
1
2 3
18 19