【问题标题】:How to remove whitespace between two paragraphs?如何删除两个段落之间的空格?
【发布时间】:2016-05-03 10:57:01
【问题描述】:

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 {

    }
}

【问题讨论】:

  • 你能发布你的代码吗?

标签: html ios iphone json swift


【解决方案1】:

如果收到html内容,可以使用NSAttributedStringUITextView中显示:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-09-01
    • 1970-01-01
    • 2020-12-01
    • 2015-07-27
    • 2014-06-14
    • 1970-01-01
    相关资源
    最近更新 更多