0

I'm working in a iOS project and I've got this HTML text that i need to display in a UITextView:

<a href="http://google.com" target="_blank" rel="nofollow" title="Link: http://google.com">http://google.com/</a><br><span class="wysiwyg-color-d24b57 ">TEST<br><i><span class="wysiwyg-color-704938 ">TEST2<br></span></i></span><div class="wysiwyg-text-align-left "><span class="wysiwyg-color-d24b57 "><span class="wysiwyg-color-704938 "><u><span class="wysiwyg-color-3a529c ">Test3<br>TEST4<br><br></span></u><span class="wysiwyg-color-3a529c wysiwyg-font-size-x-large ">Test5</span><u><span class="wysiwyg-color-3a529c "><br><br><br></span></u></span></span></div> 

So far, I've created the NSAttributedString and the UITextView:

NSAttributedString *attributedString = [[NSAttributedString alloc] initWithData: [example.text dataUsingEncoding:NSUnicodeStringEncoding] options: @{ NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType } documentAttributes: nil error: nil ]; UITextView *textView = [[UITextView alloc] init]; textView.frame = [node labelFrame]; textView.attributedText = attributedString; textView.editable = NO; textView.selectable = YES; textView.backgroundColor = [UIColor clearColor]; return textView; 

Now I have to apply the wysiwyg CSS on it, as at the moment, color, font-size and alignment are not working.

Does anybody have any idea how to to do this?

Thanks in advance!

1 Answer 1

1

You can like this way

let divHtml = "<div style=\"font-family:Helvetica;font-size:14px;line-height:22px\" >" + YOUR TEXT + "</div>" let attributedString = try! NSAttributedString(data: divHtml.dataUsingEncoding(NSUTF8StringEncoding)!, options: [NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType], documentAttributes: nil) textView.attributedText = attributedString 
Sign up to request clarification or add additional context in comments.

2 Comments

I've got different fonts, sizes and colors for different parts of the HTML text, what I need is to be able to identify tags like this inside the text: span class="wysiwyg-color-d24b57"
@jigneshVadadoriya how to add external css

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.