我有一个带帖子单元格的UITableView,在描述中到处都有空格,到处都是这样的东西:
Hello,
Text goes here   and more here and even
more
和换行符。这是一个示例帖子:
Hello, Text goes here and more here and even
more. And we have room for this now because
we don't have the line breaks.
注意大规模的断线,很奇怪&amp ;;事物和随机的三四个空格。所以我的问题是如何使描述看起来像这样:
{{1}}
如果我们能够像邮件应用程序描述一样,那就太棒了。
谢谢,
答案 0 :(得分:2)
试试这个解决方案。
ASCII_file
//调用此方法转换字符串
extension String{
func decodeEnt() -> String{
let encodedData = self.dataUsingEncoding(NSUTF8StringEncoding)!
let attributedOptions : [String: AnyObject] = [
NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType,
NSCharacterEncodingDocumentAttribute: NSUTF8StringEncoding
]
var attributedString = NSAttributedString()
do
{
attributedString = try NSAttributedString(data: encodedData, options: attributedOptions, documentAttributes: nil)
}
catch
{
print("error")
}
return attributedString.string
}