【问题标题】:Empty space in UILabel - attributed text set from HTMLUILabel 中的空白空间 - 来自 HTML 的属性文本集
【发布时间】:2017-10-15 15:46:23
【问题描述】:


我有一个带有标签的自定义 UITableViewCell,自动布局设置正确。我正在尝试像这样设置属性文本:

 dataString = [dataString stringByAppendingString:[NSString stringWithFormat:@"<style>body{font-family: 'RobotoCondensed-Regular'; font-size:11px;}</style>"]];
NSMutableAttributedString * attrStr = [[NSMutableAttributedString alloc] initWithData:[dataString dataUsingEncoding:NSUTF8StringEncoding] options:@{ NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType,NSCharacterEncodingDocumentAttribute: [NSNumber numberWithInt:NSUTF8StringEncoding] } documentAttributes:nil error:nil];
_scheduleLabel.attributedText = attrStr;

dataString 是&lt;p&gt;L-D: &lt;b&gt;10-22&lt;/b&gt;&lt;/p&gt; tableview 有 UITableViewAutomaticDimension,问题是标签在文本之后有额外的空白,它弄乱了整个布局。为什么会发生这种情况,我该如何删除它?

【问题讨论】:

    标签: html ios objective-c nsattributedstring tableviewcell


    【解决方案1】:

    这发生在我身上。我的解决方案是替换

    标签在 html 中使用 and 并删除空格。

    【讨论】:

    • 你能解释一下你的解决方案吗?看来我最后也看到了同样的问题。
    • L-D: 10-22

      替换为 L-D: 10-22
    猜你喜欢
    • 1970-01-01
    • 2011-03-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-09-13
    • 1970-01-01
    • 2022-10-01
    • 2012-09-17
    相关资源
    最近更新 更多