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: 在这里输入图像描述

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?


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 :

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

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

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

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

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


  • I found this. It supports inline text border and also block text border, which is exactly what i needed.

    链接地址: http://www.djcxy.com/p/81992.html

    上一篇: 如何从UIImageView获取显示的图像帧?

    下一篇: 具有大量减价支持的UITextView