QMChatRoomIframeCell.m 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. //
  2. // QMChatRoomIframeCell.m
  3. // IMSDK-OC
  4. //
  5. // Created by haochongfeng on 16/11/13.
  6. // Copyright © 2016年 HCF. All rights reserved.
  7. //
  8. #import "QMChatRoomIframeCell.h"
  9. #import <WebKit/WebKit.h>
  10. @interface QMChatRoomIframeCell() {
  11. WKWebView *_webView;
  12. NSString *_messageId;
  13. }
  14. @end
  15. @implementation QMChatRoomIframeCell
  16. - (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
  17. self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
  18. if (self) {
  19. [self createUI];
  20. }
  21. return self;
  22. }
  23. - (void)createUI {
  24. _webView = [[WKWebView alloc] init];
  25. [self.chatBackgroudImage addSubview:_webView];
  26. }
  27. - (void)setData: (CustomMessage *)message avater:(NSString *)avater {
  28. _messageId = message._id;
  29. self.message = message;
  30. [super setData:message avater:avater];
  31. if ([message.fromType isEqualToString:@"0"]) {
  32. // 发送
  33. }else {
  34. NSURLRequest *reqeust = [NSURLRequest requestWithURL:[NSURL URLWithString:message.message]];
  35. [_webView loadRequest:reqeust];
  36. [_webView reload];
  37. _webView.frame = CGRectMake(15, 10, (CGFloat)message.width.intValue, (CGFloat)message.height.intValue);
  38. self.chatBackgroudImage.frame = CGRectMake(CGRectGetMaxX(self.iconImage.frame)+5, CGRectGetMaxY(self.timeLabel.frame)+10, _webView.frame.size.width+30, _webView.frame.size.height+20);
  39. _webView.allowsLinkPreview = YES;
  40. _webView.scrollView.backgroundColor = [UIColor redColor];
  41. }
  42. }
  43. - (void)awakeFromNib {
  44. [super awakeFromNib];
  45. // Initialization code
  46. }
  47. - (void)setSelected:(BOOL)selected animated:(BOOL)animated {
  48. [super setSelected:selected animated:animated];
  49. // Configure the view for the selected state
  50. }
  51. @end