Text in between <b></b> programmatic bold string in between and nilling<b></b> UILabel swift
Text in between <b></b> programmatic bold string in between and nilling<b></b> UILabel swift
我有核心数据对象,其中包含以 作为标记的字符串,使该部分代码变为粗体。无论如何,有没有办法检查 swift 中的这些内容,使文本之间的文本变为粗体并使 代码对用户不可见?我对编码还是 swift 语言的新手。你会怎么做呢?这是 iOS.
var str = "<b>Hello, playground</b>"
do{
let atrString = try NSAttributedString(data:str.dataUsingEncoding(NSUTF8StringEncoding)!, options: [NSDocumentTypeDocumentAttribute:NSHTMLTextDocumentType], documentAttributes: nil)
}catch{
print("Could not convert!")
}
您首先需要使用 dataUsingEncoding()
将文本转换为 NSData,然后尝试使用 HTML 文本文档类型
制作 NSAttributedString
我有核心数据对象,其中包含以 作为标记的字符串,使该部分代码变为粗体。无论如何,有没有办法检查 swift 中的这些内容,使文本之间的文本变为粗体并使 代码对用户不可见?我对编码还是 swift 语言的新手。你会怎么做呢?这是 iOS.
var str = "<b>Hello, playground</b>"
do{
let atrString = try NSAttributedString(data:str.dataUsingEncoding(NSUTF8StringEncoding)!, options: [NSDocumentTypeDocumentAttribute:NSHTMLTextDocumentType], documentAttributes: nil)
}catch{
print("Could not convert!")
}
您首先需要使用 dataUsingEncoding()
将文本转换为 NSData,然后尝试使用 HTML 文本文档类型