Krodak
Krodak

Reputation: 1493

Rich text (with images) performance - UITextView vs UIWebview

I need to display rich text which may include a lot of images as is formatted as Markdown.

After some research I see that there are 2 most common approaches:

I'm wondering about possible issues with both approaches but mostly performance. I'm aware that with UITextView I'm a bit limited as I can't use CSS to customise its look etc., but if you had some experience and there are a lot of issues with images alignment in UITextView that would be good to know too.

Additionally, as this may be relevant to others searching for possible functionality, I'm listing libs that I'm considering to use to handle Markdown:

Upvotes: 0

Views: 1790

Answers (2)

Joshua Cleetus
Joshua Cleetus

Reputation: 672

Apple recommends the use of UITextView where possible

It’s recommended that you use a text view—and not a UIWebView object—to display both plain and rich text in your app.

Referene: UITextView

Also to customize the looks you can use any RichText Libraries, like SwiftRichString

Upvotes: 1

Tapani
Tapani

Reputation: 3231

With UIWebView you cannot get the frame size needed to display the content before it has been rendered (asynchronously). But with NSAttributedString you can get the bounds synchronously without first rendering the content. For this UIWebView is much slower.

I have used CSS with UITextView when converting HTML to NSAttributedString using DTCoreText. iOS has some own HTML to NSAttributedString conversion functions, but they are really, really slow.

Upvotes: 1

Related Questions