// // WkWebViewViewController.m // Lighting // // Created by 曹云霄 on 2016/11/24. // Copyright © 2016年 上海勾芒科技有限公司. All rights reserved. // #import "WkWebViewViewController.h" @interface WkWebViewViewController () @end @implementation WkWebViewViewController - (void)viewDidLoad { [super viewDidLoad]; } #pragma mark - 初始化 - (instancetype)initWithReturnContentSize:(void(^)(CGFloat contentHeight))block { if (self = [super init]) { self.contentWebView = [[UIWebView alloc]initWithFrame:CGRectMake(27, 0, ScreenWidth-27*2, 0.01)]; self.contentWebView.delegate = self; self.contentWebView.scrollView.scrollEnabled = NO; self.contentHeight = block; [self.view addSubview:self.contentWebView]; //下划线 UIView *lineView = [[UIView alloc]init]; lineView.backgroundColor = RGB(237, 238, 239, 1); [self.view addSubview:lineView]; [lineView mas_makeConstraints:^(MASConstraintMaker *make) { make.left.right.bottom.equalTo(self.view); make.size.mas_equalTo(CGSizeMake(ScreenWidth, 1)); }]; } return self; } - (void)setHtmlString:(NSString *)htmlString { [self.contentWebView loadHTMLString:htmlString baseURL:nil]; } #pragma mark - - (void)webViewDidStartLoad:(UIWebView *)webView { [XBLoadingView showHUDViewWithDefaultWithView:self.view];; } - (void)webViewDidFinishLoad:(UIWebView *)webView { [XBLoadingView hideHUDViewWithDefaultWithView:self.view]; CGFloat height = webView.scrollView.contentSize.height; webView.height = height; if (self.contentHeight) { self.contentHeight(height); } } - (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error { [XBLoadingView hideHUDViewWithDefaultWithView:self.view]; [XBLoadingView showHUDViewWithText:@"加载失败"]; } @end