I’m building an iOS reader app where I need to be able to highlight selections of text and optionally link notes with highlights. I’ve begun by using Text Kit (UITextView
, NSAttributedString
). I am targeting iOS 7, 8, and 9.
My problem is that I need to be able to support Drop Caps on certain paragraphs in the content. This means the first letter of a paragraph is the height of 2 lines of text and the first 2 lines of text appear beside it, then the remaining lines wrap under. My content has many drop cap characters on various paragraphs throughout.
Example showing 4-line drop cap.
Text Kit: Exclusion Paths
My initial assumption was that I would use Text Kit exclusion paths so that paragraph would wrap around it. But I can’t figure out a way to determine the exact placement of the exclusion paths and I wasn’t sure if these would float along as my content scrolls. With this approach, I would also have to manually handle text selection of the Drop Cap characters, which I’d like to avoid.
Text Kit: NSTextAttachments
I was hopeful that I could use inline Text Attachments (NSTextAttachment
), but I can’t determine a way to have 2 lines wrap beside it.
Core Text
I found a couple older (pre-TextKit) examples of Drop Cap implementations using Core Text, however, every one showed only the first character of the content as a Drop Cap and not multiple paragraphs throughout the content as I need. I was hoping to avoid Core Text also since I’d rather not handle text selection manually.
- https://stackoverflow.com/a/14469897
- https://stackoverflow.com/a/14639864
- https://stackoverflow.com/a/9272955
Current Hope/Question
NSTextAttachment
feels like the simplest approach. Is there a way to wrap 2 lines of text beside it?
Fallback... I’m beginning to wonder if I should switch to WKWebView
and drop iOS 7 -- since HTML supports drop caps and WKWebView
provides more performance than UIWebView
.