【发布时间】:2018-10-30 04:38:50
【问题描述】:
假设我从文件 (html 或 rtf) 中读取了NSAttributedString,并且在该文件中我清楚地看到了几个表格。有没有办法提取这些表或至少找到与该表对应的NSRange?如果我能以某种方式从NSAttributedString 提取(数组)NSTextTableBlock、NSTextTable 或NSTextBlock,那将是理想的。但如果这不可能,那么至少应该有一种方法可以找到表格单元格的 NSRange 或类似的东西。 Swift(可能是 4 个)是首选,但 obj-c 也可以。
例如想象这样的场景:
let html =
"""
<table style="height: 51px;" width="147">
<tbody>
<tr>
<td style="width: 65.5px;">a</td>
<td style="width: 65.5px;">b</td>
</tr>
<tr>
<td style="width: 65.5px;">c</td>
<td style="width: 65.5px;">d</td>
</tr>
</tbody>
</table>
"""
var str = NSAttributedString(html: html.data(using: .utf8)!, options: [:], documentAttributes: nil)!
然后我想或多或少地做一些这样的事情:
for table in str{
for row in table{
for cell in row{
//do something
}
}
}
【问题讨论】:
-
你能发布你需要的例子吗
标签: swift nsattributedstring rtf nsrange