小编Kon*_*ich的帖子

HTML到NSAttributedString和NSAttributedString到HTML

我有NSAttributedString的问题...

我想将HTML字符串转换为NSAttributedString,然后处理NSAttributedString(更改一些颜色,fontsize,fontfamily,background-,foreground-Color),然后转换回来自NSAttributedString的纯HTML文本.

转换不是问题,但每次我将HTML转换为NSAS并返回字体大小越来越大?!

这是我的游乐场的图片和源代码.

// Playground - noun: a place where people can play
// NSAS: - NSAttributedString

import UIKit

class Wrapper {

    //MARK: fields
    let apiHtml = "<div style='font-size: 18px'><span style='font-family:&#039;andale mono&#039;, times;'>Dies</span> <span style='font-family:&#039;comic sans ms&#039;, sans-serif;'>ist</span> <strong><span style='font-family:&#039;andale mono&#039;, sans-serif;';>eine</span></strong> <em>formatierte</em> <span style='text-decoration:underline;'>Karte</span>&#160;<span style='font-size:16px;'>die</span> <span style='background-color:#ffff00;'>es</span> zu &#220;bernehmen gilt</div>"

    var newGeneratedHtml = ""
    var textView : UITextView!

    //MARK: constructor
    init() {
        //init textview
        textView = UITextView(frame: CGRectMake(0, 0, 500, 300)) …
Run Code Online (Sandbox Code Playgroud)

html string nsattributedstring ios swift

8
推荐指数
1
解决办法
2807
查看次数

标签 统计

html ×1

ios ×1

nsattributedstring ×1

string ×1

swift ×1