Quantcast
Channel: Xamarin.Forms — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 89864

How can I fit scale of a non-responsible web page in WebView on Android and iOS platforms both?

$
0
0

Hello, everyone! I want to fit scale of a non-responsible web page loaded in WebView on Android and
iOS platforms both. To do it I created CustomWebView class inherited from the WebView. Also I created custom renderer CustomWebViewRenderer to render CustomWebView using features of concrete platform. But page is still loaded larger than screen size. Can somebody help me? Here is my code below. Thanks in advance!

public class CustomWebView: WebView{ }

[assembly: ExportRenderer(typeof(CustomWebView), typeof(CustomWebViewRenderer))]
namespace MyProject.iOS
{
    public partial class CustomWebViewRenderer : WebViewRenderer
    {
        protected override void OnElementChanged(VisualElementChangedEventArgs e)
        {
            base.OnElementChanged (e);
            if (e.OldElement == null) {
                this.ScalesPageToFit = true;
            }
        }
    }
}

<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             xmlns:local="clr-namespace:Core.Views;assembly=Core.Views"
             x:Class="XamlSamples.HelloXamlPage">
   <ContentPage.Content>
      <local:CustomWebView Source="http://tsu.tula.ru" />
   </ContentPage.Content>
</ContentPage>

Viewing all articles
Browse latest Browse all 89864

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>