我有一个textView来设置文章的内容(丰富的html文本)。
git init <directory>
从我的网站下载html字符串。我将static func setTextViewRichText(textView: UITextView, html: String) {
do{
let attributedText = try NSAttributedString(data: html.dataUsingEncoding(NSUTF8StringEncoding)!, options: [NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType, NSCharacterEncodingDocumentAttribute: NSNumber(unsignedLong: NSUTF8StringEncoding)], documentAttributes: nil)
textView.attributedText = attributedText
} catch let err as NSError {
NSLog("%s", err)
textView.text = html
}
}
类全局应用于所有图像(twitter bootstrap)。如何将此类(或类似的响应式样式)应用于我的.img-responsive
?
答案 0 :(得分:1)
只是将响应式图像样式添加到您的html
static func addResponsiveImageStyleToHtml(html: String) -> String {
return
"<head>" +
" <style>" +
" img {max-width: 100%; height: auto;}" +
" </style>" +
"</head>" +
html
}