This repository has been archived by the owner on Apr 29, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
/
Copy pathWebViewController.xib.cs
87 lines (74 loc) · 2.49 KB
/
WebViewController.xib.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
//
// Web sample in C#v
//
using System;
using UIKit;
using Foundation;
using CoreGraphics;
namespace MonoCatalog {
public partial class WebViewController : UIViewController {
UIWebView web;
// Load our definition from the NIB file
public WebViewController () : base ("WebViewController", null)
{
}
public override void ViewWillDisappear (bool animated)
{
web.StopLoading ();
web.Delegate = null;
UIApplication.SharedApplication.NetworkActivityIndicatorVisible = false;
}
public override bool ShouldAutorotateToInterfaceOrientation (UIInterfaceOrientation toInterfaceOrientation)
{
return true;
}
public override void ViewDidLoad ()
{
Title = "Web";
NavigationController.NavigationBar.Translucent = false;
var webFrame = UIScreen.MainScreen.ApplicationFrame;
webFrame.Y += 25f;
webFrame.Height -= 40f;
web = new UIWebView (webFrame) {
BackgroundColor = UIColor.White,
ScalesPageToFit = true,
AutoresizingMask = UIViewAutoresizing.FlexibleWidth | UIViewAutoresizing.FlexibleHeight
};
web.LoadStarted += delegate
{
UIApplication.SharedApplication.NetworkActivityIndicatorVisible = true;
};
web.LoadFinished += delegate
{
UIApplication.SharedApplication.NetworkActivityIndicatorVisible = false;
};
web.LoadError += (webview, args) => {
UIApplication.SharedApplication.NetworkActivityIndicatorVisible = false;
web.LoadHtmlString (String.Format ("<html><center><font size=+5 color='red'>An error occurred:<br>{0}</font></center></html>", args.Error.LocalizedDescription), null);
};
View.AddSubview (web);
// Delegate = new
var urlField = new UITextField (new CGRect (20f, 10f, View.Bounds.Width - (20f * 2f), 30f)) {
BorderStyle = UITextBorderStyle.Bezel,
TextColor = UIColor.Black,
Placeholder = "<enter a URL>",
Text = "http://ios.xamarin.com/",
BackgroundColor = UIColor.White,
AutoresizingMask = UIViewAutoresizing.FlexibleWidth,
ReturnKeyType = UIReturnKeyType.Go,
KeyboardType = UIKeyboardType.Url,
AutocapitalizationType = UITextAutocapitalizationType.None,
AutocorrectionType = UITextAutocorrectionType.No,
ClearButtonMode = UITextFieldViewMode.Always
};
urlField.ShouldReturn = delegate (UITextField field)
{
field.ResignFirstResponder ();
web.LoadRequest (NSUrlRequest.FromUrl (new NSUrl (field.Text)));
return true;
};
View.AddSubview (urlField);
web.LoadRequest (NSUrlRequest.FromUrl (new NSUrl ("http://ios.xamarin.com/")));
}
}
}