在Swift4.1和Xcode 9.3.1中我收到错误
键入' String'没有会员' documentType'
do {
let modifiedFont = NSString(format:"<span style=\"font-family: '-apple-system', 'HelveticaNeue'; font-size: 16\">%@</span>" as NSString, string) as String
let data = modifiedFont.data(using: String.Encoding.utf8, allowLossyConversion: true)
if let d = data {
let str = try NSAttributedString(data: d,
options: [.documentType : NSAttributedString.DocumentType.html],
documentAttributes: nil)
return str
}
}
答案 0 :(得分:1)
这个解决方案对我有用。
do {
let modifiedFont = NSString(format:"<span style=\"font-family: '-apple-system', 'HelveticaNeue'; font-size: 16\">%@</span>" as NSString, string) as String
let data = modifiedFont.data(using: String.Encoding.utf8, allowLossyConversion: true)
if let d = data {
let str = try NSAttributedString(data: d,
options: [NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType], documentAttributes: nil)
return str
}
} catch {
}