本文主要是介绍IOS开发之路二十一(UIWebView加载本地html),希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
挺简单不多说的直接代码:
//
// ViewController.h
// JSAndJson
//
// Created by WildCat on 13-9-8.
// Copyright (c) 2013年 wildcat. All rights reserved.
//#import <UIKit/UIKit.h>@interface ViewController : UIViewController
@property (nonatomic, strong) UIWebView *myWebView;
@end
//
// ViewController.m
// JSAndJson
//
// Created by WildCat on 13-9-8.
// Copyright (c) 2013年 wildcat. All rights reserved.
//#import "ViewController.h"@interface ViewController ()@end@implementation ViewController
@synthesize myWebView;
//加载app中html函数
- (void)loadDocument:(NSString*)docName {NSString *mainBundleDirectory = [[NSBundle mainBundle] bundlePath];NSString *path = [mainBundleDirectory stringByAppendingPathComponent:docName];NSURL *url = [NSURL fileURLWithPath:path];NSURLRequest *request = [NSURLRequest requestWithURL:url];self.myWebView.scalesPageToFit = YES;[self.myWebView loadRequest:request];
}- (void)viewDidLoad
{[super viewDidLoad];self.view.backgroundColor = [UIColor whiteColor];self.myWebView = [[UIWebView alloc] initWithFrame:self.view.bounds];self.myWebView.scalesPageToFit = YES;[self.view addSubview:self.myWebView];//app中的html[self loadDocument:@"test.html"];}- (void)viewDidUnload
{[super viewDidUnload];// Release any retained subviews of the main view.
}- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
}@end
这篇关于IOS开发之路二十一(UIWebView加载本地html)的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!