WkWebViewViewController.m 1.81 KB
Newer Older
曹云霄's avatar
曹云霄 committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
//
//  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]) {
24
        self.contentWebView = [[UIWebView alloc]initWithFrame:CGRectMake(27, 10, ScreenWidth-27*2, 0.01)];
曹云霄's avatar
曹云霄 committed
25
        self.contentWebView.delegate = self;
26
        self.contentWebView.scrollView.scrollEnabled = NO;
曹云霄's avatar
曹云霄 committed
27 28
        self.contentHeight = block;
        [self.view addSubview:self.contentWebView];
29
        //下划线
30 31 32 33
        UIView *lineView = [[UIView alloc]init];
        lineView.backgroundColor = RGB(237, 238, 239, 1);
        [self.view addSubview:lineView];
        [lineView mas_makeConstraints:^(MASConstraintMaker *make) {
34 35
            make.left.right.bottom.equalTo(self.view);
            make.size.mas_equalTo(CGSizeMake(ScreenWidth, 1));
36
        }];
曹云霄's avatar
曹云霄 committed
37 38 39 40 41 42 43 44 45 46
    }
    return self;
}

- (void)setHtmlString:(NSString *)htmlString
{
    _htmlString = htmlString;
    [self.contentWebView loadHTMLString:_htmlString baseURL:nil];
}

47 48
#pragma mark - <UIWebViewDelegate>
- (void)webViewDidStartLoad:(UIWebView *)webView
曹云霄's avatar
曹云霄 committed
49 50 51
{
    [self CreateMBProgressHUDLoding];
}
52
- (void)webViewDidFinishLoad:(UIWebView *)webView
曹云霄's avatar
曹云霄 committed
53 54
{
    [self RemoveMBProgressHUDLoding];
55
    webView.height = webView.scrollView.contentSize.height;
曹云霄's avatar
曹云霄 committed
56
    if (self.contentHeight) {
57
        self.contentHeight(webView.scrollView.contentSize.height+20);
曹云霄's avatar
曹云霄 committed
58 59 60
    }
}

61
- (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error
曹云霄's avatar
曹云霄 committed
62 63 64 65
{
    [self ErrorMBProgressView:@"加载失败"];
}

66

67

曹云霄's avatar
曹云霄 committed
68
@end