我有一个UITextView,我正在管理一个NSAttributedString,最初通过键盘正常输入.我将属性字符串保存为HTML,看起来很好.当我再次加载它,并将其转换回HTML中的属性字符串时,字体大小似乎发生了变化.
例如,加载时的HTML如下所示:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta http-equiv="Content-Style-Type" content="text/css">
<title></title>
<meta name="Generator" content="Cocoa HTML Writer">
<style type="text/css">
p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 21.0px Helvetica; color: #000000; -webkit-text- stroke: #000000}
span.s1 {font-family: 'Helvetica'; font-weight: normal; font-style: normal; font-size: 21.00pt; font-kerning: none}
</style>
</head>
<body>
<p class="p1"><span class="s1">There is some text as usual lots of text</span></p>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
我转换它并使用以下代码检查属性:
// convert to attributed string
NSError *err;
NSAttributedString *as = [[NSAttributedString alloc] …Run Code Online (Sandbox Code Playgroud) 我有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:'andale mono', times;'>Dies</span> <span style='font-family:'comic sans ms', sans-serif;'>ist</span> <strong><span style='font-family:'andale mono', sans-serif;';>eine</span></strong> <em>formatierte</em> <span style='text-decoration:underline;'>Karte</span> <span style='font-size:16px;'>die</span> <span style='background-color:#ffff00;'>es</span> zu Ü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)