UITextView Rich Text?

I was wondering if a UITextView can display rich text? I want to have simple formatting only for text with text (for example, for different parts of the text). if not, what kind should i use?

+5
source share
3 answers

Typically, the best way to do this is to use UIWebView and load local content where you can insert tags and all you need. Local loading should be fast and you can style it to look like any uitextview

Another option is to use the UILabel subclass instead and get the Three20 open-souce code. You want a TTStyledTextLabel .

+2

, - uiwebview - js . Build Phases → Compile Sources → js, html-. javascript c -.

NSString *someHtmlContent = [NSString stringWithFormat:@"<html><head><style type=\"text/css\">body {padding: 0px; margin: 0px; }</style><script src=\"yourLocalJsFile.js\"></script></head><body></body></html>", dynamicText]; 

NSLog(@"HTML with code: \n%@", someHtmlContent);

NSString *resourcePath = [[[[NSBundle mainBundle] resourcePath]
                               stringByReplacingOccurrencesOfString:@"/" withString:@"//"]
                              stringByReplacingOccurrencesOfString:@" " withString:@"%20"];

[MyWebView loadHTMLString:someHtmlContent baseURL:[NSURL URLWithString:
                                            [NSString stringWithFormat:@"file:/%@//", resourcePath]]];

[self.MyWebView setDelegate:self];

, - , -.

+2

EGOTextView github.

" UITextView, ".

+1

All Articles