UITextView中的HTML有序列表

时间:2018-03-14 16:35:36

标签: html ios objective-c uitextview nsattributedstring

我正在尝试将带有有序列表的HTML文本设置为UITextView。

NSString *bodyText = "Please follow the below points:<br><ol><li>Point number one.</li><br><li>Point number two.<br><br>Note:<br>There is point to note here.</li><br><li>Point number three.</li></ol>";

NSAttributedString *attributedString = [[NSAttributedString alloc] initWithData:[bodyText dataUsingEncoding:NSUnicodeStringEncoding] options:@{NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType} documentAttributes:nil error:nil];

self.bodyTextView.attributedText = attributedString;

上面是HTML文本,我想将其设置为我的UITextView。我屏幕上的预期结果应该是

Please follow the below points:

    1. Point number one.

    2. Point number two.

       Note:
       There is point to note here.

    3. Point number three.

但是,我在屏幕上看到的结果是,

Please follow the below points:

    1. Point number one.
    2.
    3. Point number two.

       Note:
       There is point to note here.
    4.
    5. Point number three.

有什么问题?我怎么能克服它?我不应该更改HTML文本。我如何处理应用程序中的案例?

提前致谢!

1 个答案:

答案 0 :(得分:0)

您的HTML就是问题所在。列表项之间不应该有任何<br>标记。列表项内部很好,但不在它们之间。

删除两个不必要的<br>标记,输出将是正确的。