iphone开发之使用UIWebView显示html内容
2012-08-10 17:56
555 查看
有时需要在本地读取html文件或者从服务器端获取帮助信息这一类的页面显示在视图中,我们可以使用UIWebView 中的
loadHTMLString方法来实现。
代码如下:
//
// ViewController.m
// UIWebViewTest
//
// Created by Cloay on 12-8-10.
// Copyright (c) 2012年 __MyCompanyName__. All rights reserved.
//
#import "ViewController.h"
@interface ViewController ()
@end
@implementation ViewController
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
UIWebView *webView = [[[UIWebView alloc] initWithFrame:CGRectMake(0, 100, 320, 360)] autorelease];
//使用loadHTMLString()方法显示网页内容
[webView loadHTMLString:[self getHtmlString] baseURL:nil];
[self.view addSubview:webView];
}
//读取html文件内容
- (NSString *)getHtmlString{
//文件路径
NSString *filePath = [[NSBundle mainBundle] pathForResource:@"index" ofType:@"html"];
NSString *contents = [NSString stringWithContentsOfFile:filePath encoding:NSUTF8StringEncoding error:nil];
return contents;
}
- (void)viewDidUnload
{
[super viewDidUnload];
// Release any retained subviews of the main view.
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
}
@end
有问题请留言,大家一起交流学习!
说明:转载请注明出处!
loadHTMLString方法来实现。
代码如下:
//
// ViewController.m
// UIWebViewTest
//
// Created by Cloay on 12-8-10.
// Copyright (c) 2012年 __MyCompanyName__. All rights reserved.
//
#import "ViewController.h"
@interface ViewController ()
@end
@implementation ViewController
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
UIWebView *webView = [[[UIWebView alloc] initWithFrame:CGRectMake(0, 100, 320, 360)] autorelease];
//使用loadHTMLString()方法显示网页内容
[webView loadHTMLString:[self getHtmlString] baseURL:nil];
[self.view addSubview:webView];
}
//读取html文件内容
- (NSString *)getHtmlString{
//文件路径
NSString *filePath = [[NSBundle mainBundle] pathForResource:@"index" ofType:@"html"];
NSString *contents = [NSString stringWithContentsOfFile:filePath encoding:NSUTF8StringEncoding error:nil];
return contents;
}
- (void)viewDidUnload
{
[super viewDidUnload];
// Release any retained subviews of the main view.
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
}
@end
有问题请留言,大家一起交流学习!
说明:转载请注明出处!
相关文章推荐
- iPhone开发--实时获取UIWebView中的html内容
- 使用 Ruby on Rails 和 Eclipse 开发 iPhone 应用程序之 2 :向客户端显示 iPhone 内容
- iphone开发-UIWebView 的使用
- 使用 Ruby on Rails 和 Eclipse 开发 iPhone 应用程序,第 1 部分:为 iPhone 提供内容
- 【iOS开发】UIWebView加载html时不显示网络图片解决办法
- 关于使用bean:write标签显示html内容
- Android - 灵活高效的在 Android Native App 开发中显示 HTML 内容
- iOS UIWebView UITextView UILabel 显示 HTML内容
- html中使用iframe时后面的内容不显示
- 我的iphone开发学习笔记(四)使用UIWebView,UISegmentedControl
- web开发中使用html/css全屏铺开显示
- iPhone 和 iPad的ios 开发中 利用 WebViewJavascriptBridge组件,通过 UIWebView 对Html进行双向通讯
- Android开发_WebView组件使用详解_LoadUrl直接显示网页内容
- 【HTML】使用iframe标签显示目标网页(内容)的指定区域
- 使用UIWebView中html标签显示富文本
- Android Native开发显示HTML内容
- iphone开发学习,开源之SVWebViewController,UIWebView支持后退、前进、刷新、使用Safari打开
- SilverLight商业应用程序开发---学习笔记(9)从摘要信息跳转到详细信息 导航到细节视图 在弹出窗体打开细节视图 使用DataGrid控件的行细节显示特性显示细节内容 主/从视图的实现
- 32Spannable的使用(Android显示html带图片 (表情开发))
- ios开发使用UIWebView显示多种文档