WIth iOS 7 came NSHTMLTextDocumentType
, which Im using the code below to parse html and show it in a UITextView
. It works perfectly, except with bullet points.
How can I both change the spacing on each side of the bulletpoints(the space between
the bulletpoint and the UItextView
left border and the space between the bulletpoint
and the text to the right of it)?
Also, more importantly. If the text continues on the next line, I also need it to continue at the same x position like the line above it where the bullet point text started. How can I achieve this? (Second line indentation)
I have tried using all kinds of css, but it seems that NSHTMLTextDocumentType
is still fairly limited. All I managed to to is change the color of just lists.
All help is appreciated.
Thank you in advance!
Code:
_textView.textContainer.lineBreakMode = NSLineBreakByCharWrapping;
NSString *testText = @"<p><b>This is a test with:</b></p><ul><li>test test test
test test test test test test test test test test <li>test test test test test
test <li>test test test test test <li>test test test test test test test test
test test test test <li>test test test test test test test test <li>test test
test test test test <li>test test test test test test test test test
</li></ul>";
NSDictionary *options = @{NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType};
NSData *htmlData = [testText dataUsingEncoding:NSUnicodeStringEncoding];
_attributedString = [[NSMutableAttributedString alloc] initWithData:htmlData
options:options documentAttributes:nil error:nil];
// Paragraph style
NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];
paragraphStyle.paragraphSpacing = 0;
paragraphStyle.lineHeightMultiple = 1.0f;
paragraphStyle.maximumLineHeight = 30.0f;
paragraphStyle.minimumLineHeight = 20.0f;
// Adding attributes to attributedString
[_attributedString addAttributes:@{NSParagraphStyleAttributeName:paragraphStyle}
range:NSMakeRange(0,_attributedString.length)];
[_attributedString addAttributes:@{NSFontAttributeName:font}
range:NSMakeRange(0,_attributedString.length)];
// Setting the attributed text
_textView.attributedText = _attributedString;