Ivan Alek
Ivan Alek

Reputation: 1919

UITextView with heavy markdown support

I want to implement UITextView that will be able to present markdown content, including inline Phrase and Sections as shown on this image: enter image description here

Provided NSAttributedString options are not powerful enough to achieve the border with round corners effect.

This can be done with overriding UIView and then using CoreText for laying down the text and drawing the frame borders, but with this i will lose the ability to select and copy specific parts of the text. Also highlighting urls, emails and phone numbers will be gone with this.

UIWebView is not an option because of performance issues, i will need bunch of these views shown at once.

So, does anybody have idea how to draw rounded borders around words/paragraphs with UITextView?

Upvotes: 2

Views: 4130

Answers (1)

Jamshed Alam
Jamshed Alam

Reputation: 12844

There are several way/library to do this.

Try with this code :

NSString *rawMarkdown;
const char * prose = [rawMarkdown UTF8String];  
struct buf *ib, *ob;       

 int length = rawMarkdown.length + 1;

ib = bufnew(length);
bufgrow(ib, length);
memcpy(ib->data, prose, length);
ib->size = length;

ob = bufnew(64);
markdown(ob, ib, &mkd_xhtml);

NSString *shinyNewHTML = [NSString stringWithUTF8String: ob->data];
NSLog(@"%@", shinyNewHTML);

 bufrelease(ib);
bufrelease(ob);

Taken from: What is the simplest implementation of Markdown for a Cocoa application?

Try with this good library :

  1. https://github.com/OliverLetterer/GHMarkdownParser

  2. https://github.com/toland/qlmarkdown/

  3. https://github.com/Cocoanetics/DTCoreText

  4. https://github.com/NimbusKit/attributedlabel

  5. https://github.com/TANGSEN/AttributeViewDemo

Upvotes: 4

Related Questions