繁体   English   中英

如何使用Xamarin iOS动态更改webView的高度

[英]How to change the height of webView dynamically using Xamarin iOS

我正在使用Xamarin iOS开发一个iOS应用程序,我有一个加载本地html的webView,但是webView占用了整个屏幕,所以没有地方放置后退按钮。

这是我的加载localhtml代码:

using CoreGraphics;
using Foundation;
using System;
using System.CodeDom.Compiler;
using System.IO;
using UIKit;

namespace AppName
{
    partial class View : UIViewController{


        public View(IntPtr handle) : base(handle)
        {
        }
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();

            // Perform any additional setup after loading the view, typically from a nib.
            var webView = new UIWebView(new CGRect(0, 20, View.Frame.Width, View.Frame.Height -20));
            View.AddSubview(webView);



            // Method 2 using LoadRequest
            string fileName = "Content/local.html"; // remember case-sensitive
            string localHtmlUrl = Path.Combine(NSBundle.MainBundle.BundlePath, fileName);
            webView.LoadRequest(new NSUrlRequest(new NSUrl(localHtmlUrl, false)));
            webView.ScalesPageToFit = false;
        }

        public override void DidReceiveMemoryWarning()
        {
            base.DidReceiveMemoryWarning();
            // Release any cached data, images, etc that aren't in use.
        }
    }
}

我究竟做错了什么?

var webView = new UIWebView(new CGRect(0, 20, View.Frame.Width, View.Frame.Height -20));

您将Web视图的框架设置为控制器框架的整个框架(y位置除外,您将从顶部设置为20 px)。

我认为你应该阅读UIView框架,边界和中心

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM