iOS   发布时间:2022-03-31  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了ios – 带有NSHTMLTextDocumentType的Bulletpoint间距和linebreak开始位置大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
与iOS 7来到NS HTMLTextDocumentType,其中进出口使用下面的代码来解析HTML并显示一个UITextView.它完美地工作,除了带有点子.

我如何能够改变项目符号两边的间距(两者之间的距离)
bulletpoint和UItextView左边界以及项目符号之间的空格
和右边的文本)?

而且,更重要的是.如果文本继续在下一行,我还需要它继续像它上面的线,其中子弹点的文本开始同x位置.我该如何实现
(第二行缩进)

我已经尝试过使用各种CSS,但是似乎NSHTMLTextDocumentType仍然相当有限.我所设法改变的只是列表的颜色.

所有的帮助是赞赏.

先谢谢你!

码:

_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;

解决方法

你应该可以停止一个可变的paragraphStyle,然后设置它的缩进,如:
NSMutableParagraphStyle *const bulletParagraphStyle = [paragraphStyle mutableCopy];
bulletParagraphStyle.firstLineHeadIndent = 20;
bulletParagraphStyle.tailIndent =20;

然后将此段落样式设置为仅包含项目符号的文本的范围.

(这将是一个笨拙的尝试从HTML开始,我会认为:如果你想留下那条路线可能会分成两个HTML字符串,其中一个项目符号列表,一个标题,所以您可以更容易地设置不同的属性.)

大佬总结

以上是大佬教程为你收集整理的ios – 带有NSHTMLTextDocumentType的Bulletpoint间距和linebreak开始位置全部内容,希望文章能够帮你解决ios – 带有NSHTMLTextDocumentType的Bulletpoint间距和linebreak开始位置所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。