如何删除两段之间的空格?

时间:2016-05-03 10:57:01

标签: html ios iphone json swift

My image

我从Html获取数据到文本。 现在请告诉我如何避开两段之间的空格?

  func processGetDescriptionResponse(json: JSON) {
    let status = json.dictionaryObject!["status"] as? Bool
    if status == true {
        let data = json.dictionaryValue["data"]!
        let values = data.arrayValue
        dataSourceDescription.removeAll()
        for i in 0 ..< values.count {
            let description = Description.initWithJSON(values[i])
            dataSourceDescription.append(description)

// DetailDescription.text = dataSourceDescription [i] .content

            if dataSourceDescription[i].file_url == ""
            {
                DetailImage.image = UIImage(named: "logo_two_fifty")
            }
            else
            {
            let imageURL = NSURL(string: baseURLString + dataSourceDescription[i].file_url!)


            DetailImage.kf_setImageWithURL(imageURL!, placeholderImage: nil, optionsInfo: [.Transition(ImageTransition.Fade(50))]) { (image, error, cacheType, imageURL) in
                }

            }


            DetailDescription.attributedText = convertText(dataSourceDescription[i].content!)


            print(DetailDescription.text)
        }

    } else {

    }
}

1 个答案:

答案 0 :(得分:1)

如果您收到html内容,则可以使用UITextViewNSAttributedString中显示该内容:

let htmlString = "<html><body><p>Para 1</p><p>Para 2</p></body></html>"

let attributedString = try!
    NSAttributedString(data: htmlString.dataUsingEncoding(NSUnicodeStringEncoding, allowLossyConversion: false)!,
                       options: [NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType],
                       documentAttributes: nil)

yourTextView.attributedText = attributedString