【发布时间】:2018-05-20 07:41:31
【问题描述】:
我正在尝试以编程方式构建带有表的属性字符串。我发现如果我首先像这样创建 HTML 会很容易:
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)!
但是如果我不想使用 HTML 怎么办?有没有办法以编程方式进行。可能是 NSMutableAttributedString。
【问题讨论】:
标签: swift macos swift4 nsattributedstring