3

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.

drop cap example 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.

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.

Community
  • 1
  • 1
davew
  • 1,255
  • 15
  • 27
  • Any luck? Did you find a good solution? I'm struggling with the same problem. – Tieme Nov 07 '18 at 10:30
  • @Tieme Due to the timeframe of my app, I ended up going with WKWebView and rendering my content as HTML. I used lots of JavaScript to handle highlighting of the text where the user took notes. – davew Nov 07 '18 at 14:38
  • Check. We can't leverage WebViews because we have to render native content in between text components.. I'm going to investigate https://stackoverflow.com/a/14639864/1218605. Thanks! – Tieme Nov 08 '18 at 13:27

0 Answers0