首先写一个html文件:
操作如下:
html文件编写代码:
oc和html的互调OChtmlios测试代码
然后在viewCOntroller.m中编写代码
#import "ViewController.h"
@interface ViewController ()
@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]];
}
结果如下图: