⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 webviewcontroller.m

📁 GLPaint example code from the iphone SDK
💻 M
字号:
/*File: WebViewController.mAbstract: The view controller for hosting the UIWebView feature of this sample.Version: 1.7Disclaimer: IMPORTANT:  This Apple software is supplied to you by Apple Inc.("Apple") in consideration of your agreement to the following terms, and youruse, installation, modification or redistribution of this Apple softwareconstitutes acceptance of these terms.  If you do not agree with these terms,please do not use, install, modify or redistribute this Apple software.In consideration of your agreement to abide by the following terms, and subjectto these terms, Apple grants you a personal, non-exclusive license, underApple's copyrights in this original Apple software (the "Apple Software"), touse, reproduce, modify and redistribute the Apple Software, with or withoutmodifications, in source and/or binary forms; provided that if you redistributethe Apple Software in its entirety and without modifications, you must retainthis notice and the following text and disclaimers in all such redistributionsof the Apple Software.Neither the name, trademarks, service marks or logos of Apple Inc. may be usedto endorse or promote products derived from the Apple Software without specificprior written permission from Apple.  Except as expressly stated in this notice,no other rights or licenses, express or implied, are granted by Apple herein,including but not limited to any patent rights that may be infringed by yourderivative works or by other works in which the Apple Software may beincorporated.The Apple Software is provided by Apple on an "AS IS" basis.  APPLE MAKES NOWARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION THE IMPLIEDWARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A PARTICULARPURPOSE, REGARDING THE APPLE SOFTWARE OR ITS USE AND OPERATION ALONE OR INCOMBINATION WITH YOUR PRODUCTS.IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL ORCONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTEGOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION, MODIFICATION AND/ORDISTRIBUTION OF THE APPLE SOFTWARE, HOWEVER CAUSED AND WHETHER UNDER THEORY OFCONTRACT, TORT (INCLUDING NEGLIGENCE), STRICT LIABILITY OR OTHERWISE, EVEN IFAPPLE HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.Copyright (C) 2008 Apple Inc. All Rights Reserved.*/#import "WebViewController.h"#import "Constants.h"@implementation WebViewController- (id)init{	self = [super init];	if (self)	{		// this title will appear in the navigation bar		self.title = NSLocalizedString(@"WebTitle", @"");	}	return self;}- (void)dealloc{	[myWebView release];	[urlField release];		[super dealloc];}- (void)loadView{	// the base view for this view controller	UIView *contentView = [[UIView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame]];	contentView.backgroundColor = [UIColor whiteColor];		// important for view orientation rotation	contentView.autoresizesSubviews = YES;	contentView.autoresizingMask = (UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight);			self.view = contentView;		[contentView release];	CGRect webFrame = [[UIScreen mainScreen] applicationFrame];	webFrame.origin.y += kTopMargin + 5.0;	// leave from the URL input field and its label	webFrame.size.height -= 40.0;	myWebView = [[UIWebView alloc] initWithFrame:webFrame];	myWebView.backgroundColor = [UIColor whiteColor];	myWebView.scalesPageToFit = YES;	myWebView.autoresizingMask = (UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight);	myWebView.delegate = self;	[self.view addSubview: myWebView];		CGRect textFieldFrame = CGRectMake(kLeftMargin, kTweenMargin, self.view.bounds.size.width - (kLeftMargin * 2.0), kTextFieldHeight);	urlField = [[UITextField alloc] initWithFrame:textFieldFrame];    urlField.borderStyle = UITextBorderStyleBezel;    urlField.textColor = [UIColor blackColor];    urlField.delegate = self;    urlField.placeholder = @"<enter a URL>";    urlField.text = @"http://www.apple.com";	urlField.backgroundColor = [UIColor whiteColor];	urlField.autoresizingMask = UIViewAutoresizingFlexibleWidth;	urlField.returnKeyType = UIReturnKeyGo;	urlField.keyboardType = UIKeyboardTypeURL;	// this makes the keyboard more friendly for typing URLs	urlField.autocorrectionType = UITextAutocorrectionTypeNo;	// we don't like autocompletion while typing	urlField.clearButtonMode = UITextFieldViewModeAlways;	[self.view addSubview:urlField];	[myWebView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://www.apple.com"]]];}- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation{	// we support rotation in this view controller	return YES;}// this helps dismiss the keyboard when the "Done" button is clicked- (BOOL)textFieldShouldReturn:(UITextField *)textField{	[textField resignFirstResponder];	[myWebView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:[textField text]]]];		return YES;}#pragma mark UIWebView delegate methods- (void)webViewDidStartLoad:(UIWebView *)webView{	// starting the load, show the activity indicator in the status bar	[UIApplication sharedApplication].isNetworkActivityIndicatorVisible = YES;}- (void)webViewDidFinishLoad:(UIWebView *)webView{	// finished loading, hide the activity indicator in the status bar	[UIApplication sharedApplication].isNetworkActivityIndicatorVisible = NO;}- (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error{	// load error, hide the activity indicator in the status bar	[UIApplication sharedApplication].isNetworkActivityIndicatorVisible = NO;	// report the error inside the webview	NSString* errorString = [NSString stringWithFormat:							 @"<html><center><font size=+5 color='red'>An error occurred:<br>%@</font></center></html>",							 error.localizedDescription];	[myWebView loadHTMLString:errorString baseURL:nil];}@end

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -