JXSystemImage1Cell.m 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. //
  2. // JXSystemImage1Cell.m
  3. // shiku_im
  4. //
  5. // Created by p on 2017/7/20.
  6. // Copyright © 2017年 Reese. All rights reserved.
  7. //
  8. #import "JXSystemImage1Cell.h"
  9. @interface JXSystemImage1Cell ()
  10. @property (nonatomic, strong) UIImageView *imageBackground;
  11. @property (nonatomic, strong) UIView *view;
  12. @property (nonatomic, strong) UILabel *title;
  13. @property (nonatomic, strong) UILabel *subtitle;
  14. @property (nonatomic, strong) UIImageView *imageV;
  15. @property (nonatomic, strong) UIView *lineView;
  16. @property (nonatomic, strong) UILabel *showAllLabel;
  17. @property (nonatomic, strong) UIImageView *showAllImageView;
  18. @end
  19. @implementation JXSystemImage1Cell
  20. -(void)creatUI{
  21. _imageBackground =[[UIImageView alloc]initWithFrame:CGRectZero];
  22. [_imageBackground setBackgroundColor:[UIColor clearColor]];
  23. _imageBackground.layer.cornerRadius = 6;
  24. _imageBackground.layer.masksToBounds = YES;
  25. [self.bubbleBg addSubview:_imageBackground];
  26. // _view = [[UIView alloc] initWithFrame:CGRectMake(10, 5, JX_SCREEN_WIDTH - 20, 290.5)];
  27. // _view.backgroundColor = [UIColor whiteColor];
  28. // _view.layer.cornerRadius = 3.0;
  29. // _view.layer.masksToBounds = YES;
  30. // [self.contentView addSubview:_view];
  31. _title = [[UILabel alloc] initWithFrame:CGRectMake(18, 15, kSystemImageCellWidth - 30, 30)];
  32. _title.font = SYSFONT(15.0);
  33. _title.numberOfLines = 0;
  34. _title.text = Localized(@"JXSystemImage_single");
  35. [_imageBackground addSubview:_title];
  36. _imageV = [[UIImageView alloc] initWithFrame:CGRectMake(18, CGRectGetMaxY(_title.frame) + 15, kSystemImageCellWidth - 30, 150)];
  37. [_imageBackground addSubview:_imageV];
  38. _subtitle = [[UILabel alloc] initWithFrame:CGRectMake(18, CGRectGetMaxY(_imageV.frame) + 15, kSystemImageCellWidth - 30, 30)];
  39. _subtitle.font = SYSFONT(14.0);
  40. _subtitle.textColor = [UIColor grayColor];
  41. _subtitle.numberOfLines = 0;
  42. _subtitle.text = Localized(@"JXSystemImage_single");
  43. [_imageBackground addSubview:_subtitle];
  44. _lineView = [[UIView alloc] initWithFrame:CGRectMake(18, CGRectGetMaxY(_subtitle.frame) + 15, kSystemImageCellWidth - 30, LINE_WH)];
  45. _lineView.backgroundColor = THE_LINE_COLOR;
  46. [_imageBackground addSubview:_lineView];
  47. _showAllLabel = [[UILabel alloc] initWithFrame:CGRectMake(18, CGRectGetMaxY(_lineView.frame) + 15, 100, 20)];
  48. _showAllLabel.font = SYSFONT(14.0);
  49. _showAllLabel.text = Localized(@"JX_ReadPassage");
  50. [_imageBackground addSubview:_showAllLabel];
  51. _showAllImageView = [[UIImageView alloc] initWithFrame:CGRectMake(kSystemImageCellWidth - 10 - 15, CGRectGetMaxY(_lineView.frame) + 13, 10, 15)];
  52. _showAllImageView.image = [UIImage imageNamed:@"more_flag"];
  53. [_imageBackground addSubview:_showAllImageView];
  54. }
  55. -(void)setCellData{
  56. [super setCellData];
  57. SBJsonParser * parser = [[SBJsonParser alloc] init] ;
  58. id content = [parser objectWithString:self.msg.content];
  59. // [_imageV sd_setImageWithURL:[content objectForKey:@"img"] placeholderImage:[UIImage imageNamed:@"Default_Gray" ]];
  60. NSURL *url = [NSURL URLWithString:[(NSDictionary *)content objectForKey:@"img"]];
  61. [_imageV sd_setImageWithURL:url placeholderImage:[UIImage imageNamed:@"Default_Gray"] options:SDWebImageRetryFailed completed:^(UIImage * _Nullable image, NSError * _Nullable error, SDImageCacheType cacheType, NSURL * _Nullable imageURL) {
  62. if (error) {
  63. NSLog(@"error = %@",error);
  64. dispatch_async(dispatch_get_global_queue(0, 0), ^{
  65. NSData *data = [NSData dataWithContentsOfURL:imageURL];
  66. UIImage *image = [UIImage imageWithData:data];
  67. dispatch_async(dispatch_get_main_queue(), ^{
  68. _imageV.image = image;
  69. });
  70. });
  71. }
  72. }];
  73. _title.text = [(NSDictionary *)content objectForKey:@"title"];
  74. _subtitle.text = [(NSDictionary *)content objectForKey:@"sub"];
  75. CGSize titleSize = [_title.text boundingRectWithSize:CGSizeMake(_title.frame.size.width, MAXFLOAT) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:_title.font} context:nil].size;
  76. CGRect titleFrame = _title.frame;
  77. titleFrame.size.height = titleSize.height;
  78. _title.frame = titleFrame;
  79. CGSize subtitleSize = [_subtitle.text boundingRectWithSize:CGSizeMake(_subtitle.frame.size.width, MAXFLOAT) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:_subtitle.font} context:nil].size;
  80. CGRect subtitleFrame = _subtitle.frame;
  81. subtitleFrame.size.height = subtitleSize.height;
  82. _subtitle.frame = subtitleFrame;
  83. [self setSubViewFrame];
  84. // CGRect frame = _view.frame;
  85. // frame.size.height = 230.5 + titleSize.height + subtitleSize.height;
  86. // _view.frame = frame;
  87. if(self.msg.isMySend)
  88. {
  89. self.bubbleBg.frame=CGRectMake(CGRectGetMinX(self.headImage.frame)- kSystemImageCellWidth - CHAT_WIDTH_ICON, INSETS, kSystemImageCellWidth, 260.5 + titleSize.height + subtitleSize.height);
  90. _imageBackground.frame = self.bubbleBg.bounds;
  91. _imageBackground.image = [[UIImage imageNamed:@"chat_bg_blue"]stretchableImageWithLeftCapWidth:stretch topCapHeight:stretch];
  92. }
  93. else
  94. {
  95. self.bubbleBg.frame=CGRectMake(CGRectGetMaxX(self.headImage.frame) + CHAT_WIDTH_ICON, INSETS2(self.msg.isGroup), kSystemImageCellWidth, 260.5 + titleSize.height + subtitleSize.height);
  96. _imageBackground.frame = self.bubbleBg.bounds;
  97. _imageBackground.image = [[UIImage imageNamed:@"chat_bg_white"]stretchableImageWithLeftCapWidth:stretch topCapHeight:stretch];
  98. }
  99. if (self.msg.isShowTime) {
  100. CGRect frame = self.bubbleBg.frame;
  101. frame.origin.y = self.bubbleBg.frame.origin.y + 40;
  102. self.bubbleBg.frame = frame;
  103. }
  104. [self setMaskLayer:_imageBackground];
  105. }
  106. - (void) setSubViewFrame {
  107. _imageV.frame = CGRectMake(_imageV.frame.origin.x, CGRectGetMaxY(_title.frame) + 15, _imageV.frame.size.width, _imageV.frame.size.height);
  108. _subtitle.frame = CGRectMake(_subtitle.frame.origin.x, CGRectGetMaxY(_imageV.frame) + 15, _subtitle.frame.size.width, _subtitle.frame.size.height);
  109. _lineView.frame = CGRectMake(_lineView.frame.origin.x, CGRectGetMaxY(_subtitle.frame) + 15, _lineView.frame.size.width, _lineView.frame.size.height);
  110. _showAllLabel.frame = CGRectMake(_showAllLabel.frame.origin.x, CGRectGetMaxY(_lineView.frame) + 15, _showAllLabel.frame.size.width, _showAllLabel.frame.size.height);
  111. _showAllImageView.frame = CGRectMake(_showAllImageView.frame.origin.x, CGRectGetMaxY(_lineView.frame) + 15, _showAllImageView.frame.size.width, _showAllImageView.frame.size.height);
  112. }
  113. -(void)didTouch:(UIButton*)button{
  114. [g_notify postNotificationName:kCellSystemImage1DidTouchNotifaction object:self.msg];
  115. }
  116. + (float)getChatCellHeight:(JXMessageObject *)msg {
  117. if ([msg.chatMsgHeight floatValue] > 1) {
  118. return [msg.chatMsgHeight floatValue];
  119. }
  120. float n = 0;
  121. SBJsonParser * parser = [[SBJsonParser alloc] init] ;
  122. id content = [parser objectWithString:msg.content];
  123. CGSize titleSize = [[(NSDictionary *)content objectForKey:@"title"] boundingRectWithSize:CGSizeMake(kSystemImageCellWidth - 20, MAXFLOAT) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:SYSFONT(15)} context:nil].size;
  124. CGSize subtitleSize = [[(NSDictionary *)content objectForKey:@"sub"] boundingRectWithSize:CGSizeMake(kSystemImageCellWidth - 20, MAXFLOAT) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:SYSFONT(14)} context:nil].size;
  125. if (msg.isShowTime) {
  126. n = 270.5 + titleSize.height + subtitleSize.height + 40 + INSETS;
  127. }else {
  128. n = 270.5 + titleSize.height + subtitleSize.height + INSETS;
  129. }
  130. msg.chatMsgHeight = [NSString stringWithFormat:@"%f",n];
  131. if (!msg.isNotUpdateHeight) {
  132. [msg updateChatMsgHeight];
  133. }
  134. return n;
  135. }
  136. @end