1、进入代码
NSString *pathForServiceterms = [[NSBundle mainBundle] pathForResource:@"service_terms" ofType:@"html"];
WebViewController *vc = [WebViewController webVCWithUrlStr:pathForServiceterms];
[self.navigationController pushViewController:vc animated:YES];
app的目录下有个service_terms.html的html文件
2、SVWebViewController
@interface WebViewController : SVWebViewController
继承自SVWebViewController,这个是github上面的一个开源库,https://github.com/TransitApp/SVWebViewController,
只不过这里为了处理统一方便,对这个开源库进行的改造,让他继承了BaseViewController,
而且封装了一个类方法
+ (instancetype)webVCWithUrlStr:(NSString *)curUrlStr;
3、网页加载进度指示
@property (strong, nonatomic) NJKWebViewProgress *progressProxy;
@property (strong, nonatomic) NJKWebViewProgressView *progressView;
这个也是网上的一个第三方库
https://github.com/ninjinkun/NJKWebViewProgress
4、这个类中有几点需要注意的东西:
4.1、
@interface SVWebViewController () <UIWebViewDelegate>
SVWebViewController 类本身实现了协议UIWebViewDelegate,然而:
@interface WebViewController ()<UIWebViewDelegate>
WebViewController又去实现协议UIWebViewDelegate,而且
@interface WebViewController : SVWebViewController
没有必要实现UIWebViewDelegate协议,因为本身就是多态重写。
还有一点, 这里SVWebViewController中的实现UIWebViewDelegate的方法是执行不到的
4.2、
因为NJKWebViewProgress也实现了WebViewController代理中的方法,用来设置进度,
_progressProxy = [[NJKWebViewProgress alloc] init];
self.delegate = _progressProxy; //这里通过delegate调用NJKWebViewProgress 中实现的方法
主要需要注意的点就是这几个UIWebViewDelegate的协议实现别弄混就行了。
5、右上角的分享按钮,这个就后面在分析了
- (void)shareItemClicked{
NSURL *url = self.webView.request.URL;
if (url.absoluteString && ![url.absoluteString isEmpty]) {
[CodingShareView showShareViewWithObj:self.webView];
}
}
6、一些介绍webView的网站
http://www.superqq.com/blog/2015/07/08/uiwebviewyong-fa-xiang-jie/
http://blog.csdn.net/totogo2010/article/details/7686164