Questions tagged [core-text]

Core Text is the modern text layout and rendering framework on Apple's Mac OS X and iOS operating systems.

Core Text is the modern text layout and rendering framework on Apple's Mac OS X and iOS operating systems.

On both platforms, it integrates with the Foundation framework's NSAttributedString and Core Foundation's CFAttributedString. On Mac OS X, Core Text classes are also toll-free bridged with their AppKit counterparts; for example, CTFont with NSFont. Thus, Core Text integrates very cleanly into the Cocoa text-drawing API, while at the same time being its basis.

Applications that need to do highly customized text rendering, beyond the basic capabilities provided by Cocoa and Cocoa Touch classes such as NSTextView and UITextView, will probably need to use Core Text.

Further reading:

749 questions
156
votes
16 answers

Convert HTML to NSAttributedString in iOS

I am using a instance of UIWebView to process some text and color it correctly, it gives the result as HTML but rather than displaying it in the UIWebView I want to display it using Core Text with a NSAttributedString. I am able to create and draw…
Joshua
  • 14,412
  • 21
  • 96
  • 171
114
votes
9 answers

NSAttributedString add text alignment

How can I add text alignment attribute to an NSAttributedString to center the text? Edit: Am I doing anything wrong? It doesn't seem to change the alignment. CTParagraphStyleSetting setting; setting.spec =…
aryaxt
  • 69,636
  • 87
  • 281
  • 421
60
votes
10 answers

Core Text - NSAttributedString line height done right?

I'm completely in the dark with Core Text's line spacing. I'm using NSAttributedString and I specify the following attributes on it: - kCTFontAttributeName - kCTParagraphStyleAttributeName From this the CTFrameSetter gets created and drawn to…
Schoob
  • 1,658
  • 1
  • 14
  • 18
56
votes
2 answers

Core Text calculate letter frame in iOS

I need to calculate exact bounding box for every each character (glyph) in NSAttributedString (Core Text). After putting together some code used to solve similar problems (Core Text selection, etc..), the result is quite good, but only few frames…
Lukasz
  • 19,014
  • 15
  • 77
  • 136
36
votes
4 answers

NSAttributedString superscript styling

I want to superscript all the instances of ® character in a block of text (legal disclaimer, naturally ;)) and the default way NSAttributedString is not very good. If I just let the character be and only use unmodified NSString, it is rendered the…
SaltyNuts
  • 4,658
  • 8
  • 43
  • 77
28
votes
3 answers

How does line spacing work in Core Text? (and why is it different from NSLayoutManager?)

I'm trying to draw text using Core Text functions, with a line spacing that's as close as possible to what it would be if I used NSTextView. Take this font as an example: NSFont *font = [NSFont fontWithName:@"Times New Roman" size:96.0]; The line…
Steven Vandeweghe
  • 2,120
  • 2
  • 20
  • 22
27
votes
9 answers

Multi-line NSAttributedString with truncated text

I need a UILabel subcass with multiline attributed text with support for links, bold styles, etc. I also need tail truncation with an ellipsis. None of the open source code that supports attributed text inside UILabels (TTTAttributedLabel,…
John Wright
  • 2,402
  • 4
  • 28
  • 32
26
votes
1 answer

What does it mean for a CTLine to have "string access"?

I'm trying to solve a hairy problem with UILabel, and I've gotten most of it figured out, except for one thing: I'm having a challenge understanding what it means for a CTLine to have "string access". The method that I'd like to use is…
bryanjclark
  • 5,978
  • 2
  • 31
  • 63
26
votes
6 answers

What is CG Raster Data?

I'm trying to find another memory leak in my code, and I can't seem to figure out what CG Raster Data is. While going through the VM Tracker with automatic snapshots enabled, the CG Raster Data seems to be the only part that increases. These also…
chicabella
  • 303
  • 3
  • 8
23
votes
13 answers

Calculate Font Size to Fit Frame - Core Text - NSAttributedString - iOS

I have some text which I am drawing into a fixed frame via an NSAttributedString (code below). At the moment I am hard coding the text size to 16. My question is, is there a way to calculate the best fit size for the text for the given frame ? -…
GuybrushThreepwood
  • 5,394
  • 9
  • 50
  • 110
22
votes
5 answers

How can i find the source of this font-related coretext warning in IOS13?

Working on an update of my app i notice that i get tons of warnings in the log when running the app in Xcode 11.2 on IOS13. CoreText note: Client requested name ".SFUI-Regular", it will get TimesNewRomanPSMT rather than the intended font. All…
Mathias
  • 3,215
  • 4
  • 28
  • 43
19
votes
2 answers

iOS: How do you measure the width and height of a string using Quartz?

Before I ask my questions, this is from Apple's documentation re: how to determine the width of a string using Quartz: If text measurements are important to your application, it is possible to calculate them using Quartz 2D functions. However,…
Hunter D
  • 673
  • 2
  • 8
  • 13
19
votes
3 answers

CGContextSelectFont equivalent

In iOS7 CGContextSelectFont is deprecated. Deprecation message says that I have to use Core Text, but I don't know which is the exact equivalent of this piece of code: CGContextSelectFont(context, "Helvetica", kBarLabelSize,…
rai212
  • 584
  • 1
  • 5
  • 20
19
votes
5 answers

Drop cap with NSAttributedString

I would like to do a drop cap first character in a UILabel using the attributedText NSAttributedString property only. Like this: (source: interpretationbydesign.com) I have experimented with adjusting the base line for the range of the first…
PeyloW
  • 36,308
  • 12
  • 75
  • 98
18
votes
3 answers

How Can I Draw Image with Text Wrapping on iOS?

I want to draw text just like the following style -- the image is always on the top right corner, and the text is around the image. Could anyone tell me how to implement this on iOS? Do I need to use Core Text? Thanks in advance!
nonamelive
  • 6,410
  • 8
  • 37
  • 47
1
2 3
49 50