1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
//
// WkWebViewViewController.m
// Lighting
//
// Created by 曹云霄 on 2016/11/24.
// Copyright © 2016年 上海勾芒科技有限公司. All rights reserved.
//
#import "WkWebViewViewController.h"
@interface WkWebViewViewController ()<UIWebViewDelegate>
@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 - <UIWebViewDelegate>
- (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