// // SecondTableViewCell.m // cellWebView // // Created by abc on 2018/5/28. // Copyright © 2018年 mike. All rights reserved. // #import "JXCustomerChatListCell.h" #import @interface JXCustomerChatListCell() @property (nonatomic, strong) WKWebView *newsWebView; @property (nonatomic, strong) UIView *line; @property (nonatomic,weak) UIImageView *backIconV; @property (nonatomic,weak) UIImageView *iconV; @property (nonatomic,weak) UILabel *timeL; @end @implementation JXCustomerChatListCell - (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{ self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]; if (self) { [self createView]; } return self; } - (void)createView{ UIImageView *iconV=[[UIImageView alloc]init]; iconV.image=[UIImage imageNamed:@"ALOGO_1200"]; iconV.backgroundColor=[UIColor greenColor]; iconV.contentMode=UIViewContentModeScaleToFill; [self.contentView addSubview:iconV]; self.iconV=iconV; iconV.frame = CGRectMake(20, 10, 50, 50); UIImageView *backIconV=[[UIImageView alloc]init]; backIconV.backgroundColor=[UIColor whiteColor]; backIconV.layer.cornerRadius=12; backIconV.layer.masksToBounds=YES; [self.contentView addSubview:backIconV]; backIconV.frame = CGRectMake(80,10,[UIScreen mainScreen].bounds.size.width-100 , 0); self.backIconV=backIconV; UILabel *timeL=[[UILabel alloc]init]; [backIconV addSubview:timeL]; timeL.frame = CGRectMake(80,10,[UIScreen mainScreen].bounds.size.width-100 , 0); self.timeL=timeL; self.newsWebView = [[WKWebView alloc] init]; self.newsWebView.frame = CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width-100, 0); self.newsWebView.navigationDelegate = self; self.newsWebView.backgroundColor=[UIColor whiteColor]; self.newsWebView.scrollView.scrollEnabled = NO; [self.newsWebView sizeToFit]; [backIconV addSubview:self.newsWebView]; } - (void)refreshWebView:(chatListModel *)url indexPath:(NSInteger)index{ self.indexPath = index; NSString *headerString = @"
"; [self.newsWebView loadHTMLString:[headerString stringByAppendingString:url.content] baseURL:nil]; self.timeL.text=[self timeFormate:url.createTime]; } - (void)webView:(WKWebView *)webView didStartProvisionalNavigation:(WKNavigation*)navigation{ } - (void)webView:(WKWebView *)webView didFinishNavigation:(WKNavigation*)navigation{ [webView evaluateJavaScript:@"document.body.scrollHeight"completionHandler:^(id _Nullable result,NSError * _Nullable error){ CGFloat height = [result floatValue]; _backIconV.frame = CGRectMake(80, 0, [UIScreen mainScreen].bounds.size.width-100, height+40); self.newsWebView.frame = CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width-100, height); self.timeL.frame = CGRectMake(JX_SCREEN_WIDTH/2-110, height+10, JX_SCREEN_WIDTH/2, 15); [self.delegate webViewDidFinishLoad:height cellIndex:self.indexPath]; }]; } - (void)layoutSubviews{ [super layoutSubviews]; } - (void)setFrame:(CGRect)frame{ frame.origin.y+=20; frame.size.height-=20; // frame.origin.x+=10; // frame.size.width=self.contentView.frame.size.width-20; [super setFrame:frame]; } - (NSString *)timeFormate:(NSString *)timeS{ NSTimeInterval time=[timeS doubleValue]+28800;//因为时差问题要加8小时 == 28800 sec NSDate *detaildate=[NSDate dateWithTimeIntervalSince1970:time/1000]; //NSLog(@"date:%@",[detaildate description]); //实例化一个NSDateFormatter对象 NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init]; //设定时间格式,这里可以设置成自己需要的格式 [dateFormatter setDateFormat:@"yyyy-MM-dd HH:mm"]; NSString *currentDateStr = [dateFormatter stringFromDate: detaildate]; return currentDateStr; } @end