アプリ開発(23) - ローカルhtmlファイルを読込む [iPadアプリ開発]
ローカルhtmlファイルを読込む方法です。
画面を読込んだ時に、1.htmlファイルを表示する方法です。
200x200のサイズの表示エリア(UIWebView)に表示します。
- (void)viewDidLoad
{
[super viewDidLoad];
html5view = [[UIWebView alloc] initWithFrame:CGRectMake(150,150,200,200)];
NSData *htmlData=[NSData dataWithContentsOfFile:[[[NSBundle mainBundle] bundlePath]
stringByAppendingPathComponent:@"1.html"]];
[html5view loadData:htmlData MIMEType:@"text/html" textEncodingName:@"utf-8" baseURL:nil];
[[html5view.subviews objectAtIndex:0] setScrollEnabled:NO];
[[html5view.subviews objectAtIndex:0] setBounces:NO];
[[self view] addSubview:html5view];
/*
NSString *path = [[NSBundle mainBundle] pathForResource:@"10" ofType:@"html"];
[self.webView loadRequest:[NSURLRequest requestWithURL:[NSURL fileURLWithPath:path]]];
*/
}
コメントアウトしている方法でも表示できますが、data loadを使う方が良いこともあります。今から晩ご飯作りなので、理由は後日。
画面を読込んだ時に、1.htmlファイルを表示する方法です。
200x200のサイズの表示エリア(UIWebView)に表示します。
- (void)viewDidLoad
{
[super viewDidLoad];
html5view = [[UIWebView alloc] initWithFrame:CGRectMake(150,150,200,200)];
NSData *htmlData=[NSData dataWithContentsOfFile:[[[NSBundle mainBundle] bundlePath]
stringByAppendingPathComponent:@"1.html"]];
[html5view loadData:htmlData MIMEType:@"text/html" textEncodingName:@"utf-8" baseURL:nil];
[[html5view.subviews objectAtIndex:0] setScrollEnabled:NO];
[[html5view.subviews objectAtIndex:0] setBounces:NO];
[[self view] addSubview:html5view];
/*
NSString *path = [[NSBundle mainBundle] pathForResource:@"10" ofType:@"html"];
[self.webView loadRequest:[NSURLRequest requestWithURL:[NSURL fileURLWithPath:path]]];
*/
}
コメントアウトしている方法でも表示できますが、data loadを使う方が良いこともあります。今から晩ご飯作りなので、理由は後日。
コメント 0