1

I have an formatted HTML string and want to load it in a wkwebview and scale it so that it fits in height and width of the wkwebviews frame.

I have already tried playing around with adding a viewport to the HTML but I just managed it to scale in widht but not to the height.

var test = "<html><head><meta name='viewport' content='width=150, user-scalable=no'><style>* {margin:0;padding:0;}body {font-weight: normal;line-height:1.3;font-family: 'Helvetica Neue',Helvetica,Arial,sans-serif;background-color: transparent;font-size:12px; }</style></head><body><div><div style =\"background:rgb(63, 63, 63);height:100%;padding:5px 5px 5px 30px;text-align:left;\"><span style=\"color:#ffffff;font-family:'Open Sans', sans-serif;\">The EU General Data Protection Regulation</span></div></div></body></html";

var webview = new WKWebView(new CGRect(10, 10, 150, 30), new WKWebViewConfiguration() { Preferences = new WKPreferences() { } });
webview.LoadHtmlString(test, null);

View.AddSubview(webview);

Does anybody have any idea how to achieve this?

Hannes Gant
  • 43
  • 1
  • 8
  • there is nothing to do on web view, this is the HTML's job to fit the sizes – GIJOW Apr 19 '18 at 15:52
  • You can adjust scale in `webViewDidFinishLoad` or use HTML style string , Details refer to [here](https://stackoverflow.com/a/10702542/8187800). – ColeX Apr 20 '18 at 07:28
  • @ColeXia-MSFT nice link but I'm using WKWebview and not UIWebview or can I do the same with WKWebview? – Hannes Gant Apr 23 '18 at 07:38
  • @HannesGant Yes, of course. – ColeX Apr 23 '18 at 07:41
  • @ColeXia-MSFT I tried changing the zoomscale for the scrollview and it works for the text. But my problem now is that the background height 100% does also scale so the background does not fill anymore the whole webview. do you have any idea how to handle this? – Hannes Gant Apr 23 '18 at 09:36

0 Answers0