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

时间:2015-07-31 15:38:19

标签: ios webview xamarin xamarin.ios

您好我正在使用Xamrian 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.
        }
    }
}

我做错了什么?

提前致谢!

1 个答案:

答案 0 :(得分:0)

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

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

我认为你应该阅读UIView frame, bounds and center