zoukankan      html  css  js  c++  java
  • iPhone控件之UIWebView2

     1 #import <UIKit/UIKit.h>
    2
    3 @interface UITestViewController : UIViewController <UIWebViewDelegate>
    4 {
    5
    6 }
    7
    8 @end
    9
    10
    11 //
    12 // UITestViewController.m
    13 // UITest
    14 //
    15
    16 #import "UITestViewController.h"
    17
    18 @implementation UITestViewController
    19
    20 - (void)viewDidLoad {
    21
    22 [super viewDidLoad];
    23
    24 CGRect webRect = CGRectMake(10,10,300,400);
    25 UIWebView *myWebView = [[UIWebView alloc] initWithFrame:webRect];
    26
    27 myWebView.delegate = self;
    28
    29 myWebView.scalesPageToFit = NO;
    30 NSString *htmlPath = [[NSBundle mainBundle] pathForResource:@"myPage" ofType:@"html"];
    31 NSString *htmlContent = [NSString stringWithContentsOfFile:htmlPath encoding:NSUTF8StringEncoding error:nil];
    32
    33 [myWebView loadHTMLString:htmlContent baseURL:nil];
    34
    35 [self.view addSubview:myWebView];
    36
    37 [myWebView release];
    38 }
    39
    40 - (BOOL)webView:(UIWebView *)webView
    41 shouldStartLoadWithRequest:(NSURLRequest *)request
    42 navigationType:(UIWebViewNavigationType)navigationType {
    43 NSURL *pageURL = [request URL];
    44
    45 if ( ([[pageURL scheme] isEqualToString: @"http"]) && (navigationType == UIWebViewNavigationTypeLinkClicked ))
    46 {
    47 [[UIApplication sharedApplication] openURL:pageURL];
    48 return NO;
    49 }
    50
    51 return YES;
    52 }
    53
    54
    55 - (void)didReceiveMemoryWarning {
    56 // Releases the view if it doesn't have a superview.
    57 [super didReceiveMemoryWarning];
    58
    59 // Release any cached data, images, etc that aren't in use.
    60 }
    61
    62 - (void)viewDidUnload {
    63 // Release any retained subviews of the main view.
    64 // e.g. self.myOutlet = nil;
    65 }
    66
    67
    68 - (void)dealloc {
    69
    70 [super dealloc];
    71 }
    72
    73 @end
  • 相关阅读:
    python面向对象(一)
    ls和cd命令详解
    SHELL 中的变量
    Shell基础
    Python版飞机大战
    Python模块制作
    Linux的cut命令
    Linux中的wc命令
    Ubuntu系统下adb devices 不能显示手机设备
    app耗电量测试工具--PowerTutor
  • 原文地址:https://www.cnblogs.com/foxmin/p/2393664.html
Copyright © 2011-2022 走看看