首先写一个html文件:
操作如下:
html文件编写代码:
<html>
<head>
<meta charset="UTF-8">
<title>oc和html的互调</title>
</head>
<body>
<h1>OC</h1>
<h1>html</h1>
<h1>ios测试代码</h1>
</body>
</html>
然后在viewCOntroller.m中编写代码
#import "ViewController.h"
@interface ViewController ()<UIWebViewDelegate>
@property (nonatomic,strong) UIWebView *webView;
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
//加载一个网页页面
self.webView = [[UIWebView alloc]initWithFrame:self.view.frame];
[self.view addSubview:self.webView];
//读取html文件
NSURL *URL = [[NSBundle mainBundle]URLForResource:@"File" withExtension:@"html"];
//加载html文件代码
[self.webView loadRequest:[NSURLRequest requestWithURL:URL]];
}
结果如下图: