IOS 开发学习34 使用webview

1 基本使用

#import 

@interface ViewController : UIViewController<UIWebViewDelegate>

@end
#import "ViewController.h"

@interface ViewController ()
{
    UIWebView *webview;
}
@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    webview=[[UIWebView alloc]initWithFrame:CGRectMake(0,0,self.view.frame.size.width,self.view.frame.size.height)];
    webview.backgroundColor = [UIColor clearColor];
    webview.scalesPageToFit =YES;
    webview.delegate =self;

    NSURLRequest *request=[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://baidu.com"]];
    [self.view addSubview:webview];
    [webview loadRequest:request];
}

2 执行js

NSString *js_result = [webview stringByEvaluatingJavaScriptFromString:@"document.write('hello');"];

你可能感兴趣的:(#,IOS/MAC)