[英]Swift - Scale UIWebView to size of content
因此,我有一個UIWebView的子類,在這個UIWebView中,我將在Swift中使用MathJax顯示數學表達式。 我想做的是像UILabel一樣使用WebView,因此我禁用了userInteraction和scrolling 。 我找到了這個 :
lview.loadLatexString(latexString: "Hello !")
lview.frame.size.height = 1
lview.frame.size = lview.sizeThatFits(CGSize.zero)
但這是行不通的。 我有這個 :
我想要這個 :
我希望這可以澄清我的問題。
您可以用於禁用webview
和UserInteraction
的滾動
myWebView.scrollView.isScrollEnabled = false
myWebView.isUserInteractionEnabled = false
嘗試使用UITextView。
禁用滾動和用戶輸入,textview將根據內容調整大小。 確保您給出適當的約束
let theString : String = "</p><img src='https://pbs.twimg.com/profile_images/655066410087940096/QSUlrrlm.png' width=100 height=100 /><h2>Subheader</h2>"
let theAttributedString = try! NSAttributedString(data: theString.data(using: String.Encoding.utf8, allowLossyConversion: false)!,options: [NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType], documentAttributes: nil)
textview.attributedText = theAttributedString
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.