我的 html 标签来自响应 json
"<strong>Volume:<\/strong> 5TB<br \/><strong>Transmission:<\/strong> FTP<br \/><strong>Validity:<\/strong> 1 Year"
实际上,如果这是标签,我可以调整 UITableViewCell
的大小。
但是,对于UITextView
,我不知道如何根据我的内部html长度调整它的大小。上面的标签只是一个例子,可能会或多或少。
任何帮助在 UITextView
中显示 html 并根据 UITextView
调整 UITableViewCell
大小
最佳答案
根据UITextView设置单元格大小
首先在View类中添加代码
override func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {
return UITableViewAutomaticDimension
}
override func tableView(tableView: UITableView, estimatedHeightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {
return UITableViewAutomaticDimension
}
只需向 UITextView 添加从各边 8px 的约束
并取消选中 UITextView 的滚动启用
对于 UITextView 内的 HTML :
关于html - 通过根据 html 标签调整单元格大小,使用 UITextView 在 UITableViewCell 中显示 html [不是 UILabel!],我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36448203/