簡體   English   中英

UIWebView內容寬度為自定義大小

[英]UIWebView content width to custom size

我在UIWebView顯示Disqus網頁。 該頁面具有移動版本,可調整其對設備的視圖大小。 我的問題是UIWebView將其內容設置為設備寬度,而我的webView大約是設備寬度的一半。 因此,我可以將我的webview向右和向左滾動。 我已經嘗試過這樣的事情: SOF問題 ,設置contentSize等但沒有結果。

您可以嘗試入侵webview css並嘗試將其寬度更改為您的屏幕寬度/ 2。

我已經完成了以下代碼片段,它完全有效:

[aWebView loadRequest:aRequest progress:nil success:^NSString *(NSHTTPURLResponse *response, NSString *HTML) {
    NSMutableString *mutableString = [[NSMutableString alloc] initWithString:HTML];
    NSRange range = [mutableString rangeOfString:@"width=device-width"]; // or whatever you have in response
    [mutableString replaceCharactersInRange:range withString:[NSString stringWithFormat:@"width=%d", (int)CGRectGetWidth(aWebView.frame)]];
    return mutableString;
} failure:nil];

感謝我的同事的想法。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM