2016-01-04 42 views
1

我有一個textView來設置文章(富HTML文本)的內容。UITextView HTML爲圖像應用響應式CSS

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 
    } 
} 

html字符串從我的網站下載。我將全球範圍內的.img-responsive課程應用於所有圖片(twitter bootstrap)。如何申請這個類(或類似的響應樣式我UITextView

回答

1

只是在前面加上響應的影像風格到您的HTML

static func addResponsiveImageStyleToHtml(html: String) -> String { 
    return 
     "<head>" + 
     " <style>" + 
     "  img {max-width: 100%; height: auto;}" + 
     " </style>" + 
     "</head>" + 
     html 
} 
+0

我可以申請bootstrap.min.css @約翰 –