JXCustomerChatListCell.m 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. //
  2. // SecondTableViewCell.m
  3. // cellWebView
  4. //
  5. // Created by abc on 2018/5/28.
  6. // Copyright © 2018年 mike. All rights reserved.
  7. //
  8. #import "JXCustomerChatListCell.h"
  9. #import <WebKit/WebKit.h>
  10. @interface JXCustomerChatListCell()<WKNavigationDelegate>
  11. @property (nonatomic, strong) WKWebView *newsWebView;
  12. @property (nonatomic, strong) UIView *line;
  13. @property (nonatomic,weak) UIImageView *backIconV;
  14. @property (nonatomic,weak) UIImageView *iconV;
  15. @property (nonatomic,weak) UILabel *timeL;
  16. @end
  17. @implementation JXCustomerChatListCell
  18. - (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
  19. self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
  20. if (self) {
  21. [self createView];
  22. }
  23. return self;
  24. }
  25. - (void)createView{
  26. UIImageView *iconV=[[UIImageView alloc]init];
  27. iconV.image=[UIImage imageNamed:@"ALOGO_1200"];
  28. iconV.backgroundColor=[UIColor greenColor];
  29. iconV.contentMode=UIViewContentModeScaleToFill;
  30. [self.contentView addSubview:iconV];
  31. self.iconV=iconV;
  32. iconV.frame = CGRectMake(20, 10, 50, 50);
  33. UIImageView *backIconV=[[UIImageView alloc]init];
  34. backIconV.backgroundColor=[UIColor whiteColor];
  35. backIconV.layer.cornerRadius=12;
  36. backIconV.layer.masksToBounds=YES;
  37. [self.contentView addSubview:backIconV];
  38. backIconV.frame = CGRectMake(80,10,[UIScreen mainScreen].bounds.size.width-100 , 0);
  39. self.backIconV=backIconV;
  40. UILabel *timeL=[[UILabel alloc]init];
  41. [backIconV addSubview:timeL];
  42. timeL.frame = CGRectMake(80,10,[UIScreen mainScreen].bounds.size.width-100 , 0);
  43. self.timeL=timeL;
  44. self.newsWebView = [[WKWebView alloc] init];
  45. self.newsWebView.frame = CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width-100, 0);
  46. self.newsWebView.navigationDelegate = self;
  47. self.newsWebView.backgroundColor=[UIColor whiteColor];
  48. self.newsWebView.scrollView.scrollEnabled = NO;
  49. [self.newsWebView sizeToFit];
  50. [backIconV addSubview:self.newsWebView];
  51. }
  52. - (void)refreshWebView:(chatListModel *)url indexPath:(NSInteger)index{
  53. self.indexPath = index;
  54. 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>";
  55. [self.newsWebView loadHTMLString:[headerString stringByAppendingString:url.content] baseURL:nil];
  56. self.timeL.text=[self timeFormate:url.createTime];
  57. }
  58. - (void)webView:(WKWebView *)webView didStartProvisionalNavigation:(WKNavigation*)navigation{
  59. }
  60. - (void)webView:(WKWebView *)webView didFinishNavigation:(WKNavigation*)navigation{
  61. [webView evaluateJavaScript:@"document.body.scrollHeight"completionHandler:^(id _Nullable result,NSError * _Nullable error){
  62. CGFloat height = [result floatValue];
  63. _backIconV.frame = CGRectMake(80, 0, [UIScreen mainScreen].bounds.size.width-100, height+40);
  64. self.newsWebView.frame = CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width-100, height);
  65. self.timeL.frame = CGRectMake(JX_SCREEN_WIDTH/2-110, height+10, JX_SCREEN_WIDTH/2, 15);
  66. [self.delegate webViewDidFinishLoad:height cellIndex:self.indexPath];
  67. }];
  68. }
  69. - (void)layoutSubviews{
  70. [super layoutSubviews];
  71. }
  72. - (void)setFrame:(CGRect)frame{
  73. frame.origin.y+=20;
  74. frame.size.height-=20;
  75. // frame.origin.x+=10;
  76. // frame.size.width=self.contentView.frame.size.width-20;
  77. [super setFrame:frame];
  78. }
  79. - (NSString *)timeFormate:(NSString *)timeS{
  80. NSTimeInterval time=[timeS doubleValue]+28800;//因为时差问题要加8小时 == 28800 sec
  81. NSDate *detaildate=[NSDate dateWithTimeIntervalSince1970:time/1000];
  82. //NSLog(@"date:%@",[detaildate description]);
  83. //实例化一个NSDateFormatter对象
  84. NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
  85. //设定时间格式,这里可以设置成自己需要的格式
  86. [dateFormatter setDateFormat:@"yyyy-MM-dd HH:mm"];
  87. NSString *currentDateStr = [dateFormatter stringFromDate: detaildate];
  88. return currentDateStr;
  89. }
  90. @end