为什么转换后的html字符串只显示第一行?
我尝试将为什么转换后的html字符串只显示第一行?,html,ios,swift,nsattributedstring,Html,Ios,Swift,Nsattributedstring,我尝试将html代码转换为属性字符串,然后在标签中使用。但出于某种原因,它只显示了第一行:“在继续之前:”所有其他内容都是空白的。我已经扩展了标签约束以填充整个屏幕,以确保没有问题。这个html代码片段已经过android的测试,效果很好 let mystring = """ <body> <p><b>Before proceeding:</b></p>
html
代码转换为属性字符串
,然后在标签中使用。但出于某种原因,它只显示了第一行:“在继续之前:”所有其他内容都是空白的。我已经扩展了标签
约束以填充整个屏幕,以确保没有问题。这个html
代码片段已经过android
的测试,效果很好
let mystring = """
<body>
<p><b>Before proceeding:</b></p>
<ul type="dash">
<li>Save a backup copy of the door configuration file</li><li>Disconnect all other devices</li></ul>
<p><b>During upgrade:</b></p>
<ul type="dash">
<li>Do not turn off phone</li>
</ul>
<p><b>Are you sure you want to upgrade?</b></p>
</body>
"""
var attrString: NSAttributedString? {
guard let data = mystring.data(using: .utf8) else { return nil }
do {
return try NSAttributedString(data: data, options: [.documentType: NSAttributedString.DocumentType.html, .characterEncoding:String.Encoding.utf8.rawValue], documentAttributes: nil)
} catch {
return nil
}
}
mylabel.attributedText = attrString
让mystring=”“”
在进行之前:
- 保存车门配置文件的备份副本
- 断开所有其他设备的连接
升级期间:
- 不要关掉电话
您确定要升级吗
"""
var attrString:NSAttributeString?{
guard let data=mystring.data(使用:.utf8)else{return nil}
做{
返回try NSAttributedString(数据:数据,选项:[.documentType:NSAttributedString.documentType.html、.characterEncoding:String.Encoding.utf8.rawValue],documentAttribute:nil)
}抓住{
归零
}
}
mylabel.AttributeText=attrString
有什么我遗漏的吗?可能不太明显,但 起初,当文本足够长时,
UILabel
的Number-of-line
属性似乎允许换行
然而
UILabel
的Number of Lines
属性还控制显示的行数,即使文本中嵌入了换行符
设置mylabel.numberOfLines=0将解决此问题。您在标签上设置了行数=0吗?天哪,谢谢,就是这样LOL