123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128 |
- //
- // SecondTableViewCell.m
- // cellWebView
- //
- // Created by abc on 2018/5/28.
- // Copyright © 2018年 mike. All rights reserved.
- //
- #import "JXCustomerChatListCell.h"
- #import <WebKit/WebKit.h>
- @interface JXCustomerChatListCell()<WKNavigationDelegate>
- @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:@"jixin"];
- 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 = @"<header><meta name='viewport' content='width=device-width, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0, user-scalable=no'></header>";
- [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
|