RichTextView

Ahmed Elkady
Dec 1, 2018 · 2 min read

Imagine you are an iOS developer, and you’re asked to build a label that renders HTML. That’s easy, you can just use NSAttributedString and pass in an HTML document type, letting that work its magic.

What if you’re now asked to display Markdown along with HTML? Well, you can either find a Markdown parser or build your own, and somehow reconcile that with the HTML.

What if you are then asked to display LaTeX, or YouTube/Vimeo links? Then you have to worry about WKWebView and proper layouts and constraints.

Well, no more.

Introducing RichTextView, a subclass of UIView that handles all of the above rich text data types

How It Works

In order for the RichTextView to handle the various use cases it might encounter, the input string needs to be formatted correctly. You can check out the appropriate input formats at our project website.

Once the input is formatted appropriately, the Youtube/Vimeo links are rendered using WKWebViews and the rest of the rich text using NSAttributedStrings in UILabels . Then, the RichTextView will use SnapKit to dynamically constrain the views one on top of another in the order they appear in the input string.

What If I Want RichTextView To Support Additional Rich Text Types?

RichTextView is designed to easily support adding more rich text types as necessary. If you would like to see something supported feel free to contribute to our repo.

Summary

In short, RichTextView is a powerful tool that can be used to render various kinds of rich text types. It is designed and built in Swift, and once implemented in your project will handle any kind of input you throw at it, as long as it is formatted appropriately.

RichTextView can be integrated into your iOS app using Cocoapods or Carthage, making it easy to start using in your app today!

Top Hat Engineering Blog

All things Engineering @ Top Hat

Ahmed Elkady

Written by

iOS Developer

Top Hat Engineering Blog

All things Engineering @ Top Hat

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade