Search code examples
iosobjective-cuitextviewcore-text

Displaying custom text in a textview


I have a data object and want to display it in a text view. It is inside a view that looks almost like an email view.

The object I have has an array of "selections" each with a "name" and "value". The value property could be several lines of text.

The name field is the description of the selection (i.e. "Name", "Address", "Comments", etc)

I'd like to display it something like this...

Name
    - Fogmeister
Address
    - 1 The Street
    - Town
    - Country
Comments
    - This is a long comment and
      spans over several lines breaking
      where necessary and has an indent.

I've got everything working except for the text that spans multiple lines.

Ideally I'd like to use an attributed string to bold the names but it hs to work with iOS 5 so I can't.

Question, is there a better way to do this than using a UITextView? The text is not editable at all. I suppose I could render it myself using core text? Would that allow me to use different text styles (bold, etc...)?


Solution

  • Use an UIWebview and then use HTML to render what ever you want.

    eg-:

        UIWebView *webView = [[UIWebView alloc] init];
        NSString *htmlString =  [NSString stringWithString:@"<html><body><h1>Head</h1><p>para</p></body></html>"];
        [webView loadHTMLString:htmlString baseURL:nil];
        [self.view addSubview:webView];