iPhone控制項之UIWebView

來源:互聯網
上載者:User
 1 #import <UIKit/UIKit.h>
2
3 @interface UITestViewController : UIViewController <UIWebViewDelegate>
4 {
5
6 }
7
8 @end
9
10
11
12
13 //
14 // UITestViewController.m
15 // UITest
16 //
17
18 #import "UITestViewController.h"
19
20 UIActivityIndicatorView *activity;
21
22 @implementation UITestViewController
23
24 - (void)viewDidLoad {
25
26 [super viewDidLoad];
27
28 [self.view setBackgroundColor:[UIColor blackColor]];
29
30 CGRect webRect = CGRectMake(10,10,300,380);
31 UIWebView *myWebView = [[UIWebView alloc] initWithFrame:webRect];
32 myWebView.scalesPageToFit = YES;
33
34 myWebView.delegate = self;
35
36 NSURL *url = [NSURL URLWithString:@"http://www.google.com"];
37 NSURLRequest *request = [NSURLRequest requestWithURL:url];
38 [myWebView loadRequest:request];
39
40 [self.view addSubview:myWebView];
41
42 activity = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
43 [activity setCenter:CGPointMake(160,420)];
44 [self.view addSubview:activity];
45
46 [myWebView release];
47 }
48
49 - (void)webViewDidStartLoad:(UIWebView *)webView
50 {
51 [activity startAnimating];
52 }
53
54 - (void)webViewDidFinishLoad:(UIWebView *)webView
55 {
56 [activity stopAnimating];
57 [webView stringByEvaluatingJavaScriptFromString:@"alert('Finished Loading!');"];
58 }
59
60 - (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error
61 {
62 [activity stopAnimating];
63 NSLog(@"Error: %@",error);
64 }
65
66 - (void)didReceiveMemoryWarning {
67 // Releases the view if it doesn't have a superview.
68 [super didReceiveMemoryWarning];
69
70 // Release any cached data, images, etc that aren't in use.
71 }
72
73 - (void)viewDidUnload {
74 // Release any retained subviews of the main view.
75 // e.g. self.myOutlet = nil;
76 }
77
78
79 - (void)dealloc {
80
81 [activity release];
82 [super dealloc];
83 }
84
85 @end

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.