相关疑难解决方法(0)

将属性字符串转换为"简单"标记的html

我想将NSAttributedString转换为html,如下所示:

This is a <i>string</i> with some <b>simple</b> <i><b>html</b></i> tags in it.
Run Code Online (Sandbox Code Playgroud)

不幸的是,如果你使用apple的内置系统,它会生成详细的基于CSS的html.(以下示例供参考)

那么如何从NSAttributedString生成简单的标记html?

我写了一篇非常详细,脆弱的电话来做这件事,这是一个糟糕的解决方案.

func simpleTagStyle(fromNSAttributedString att: NSAttributedString)->String {

    // verbose, fragile solution

    // essentially, iterate all the attribute ranges in the attString
    // make a note of what style they are, bold italic etc
    // (totally ignore any not of interest to us)
    // then basically get the plain string, and munge it for those ranges.
    // be careful with the annoying "multiple attribute" case
    // (an alternative …
Run Code Online (Sandbox Code Playgroud)

html markdown nsattributedstring swift

4
推荐指数
1
解决办法
1082
查看次数

标签 统计

html ×1

markdown ×1

nsattributedstring ×1

swift ×1