2

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?

Ivan Alek
  • 1,899
  • 3
  • 19
  • 38
  • 1
    Does [this](http://stackoverflow.com/a/18886718/1489885) help? Maybe you can draw the box in HTML/CSS easily. – HAS Oct 11 '16 at 15:47
  • I tried this, but it takes way too long to load. Even for very simple few words string it takes around 1 sec. – Ivan Alek Oct 12 '16 at 19:18
  • I found [this](https://github.com/ibireme/YYText). It supports inline text border and also block text border, which is exactly what i needed. – Ivan Alek Oct 15 '16 at 12:52

1 Answers1

4

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

Community
  • 1
  • 1
Jamshed Alam
  • 12,424
  • 5
  • 26
  • 49