HomeTableViewCell.m 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  1. //
  2. // HomeTableViewCell.m
  3. // TheoryNetwork
  4. //
  5. // Created by tederen on 2019/9/26.
  6. // Copyright © 2019 tederen. All rights reserved.
  7. //
  8. #import "HomeTableViewCell.h"
  9. #import "DocumentModel.h"
  10. #import "FLAnimatedImage.h"
  11. @interface HomeTableViewCell ()
  12. @property (weak, nonatomic) IBOutlet UILabel *titleLabel;
  13. @property (weak, nonatomic) IBOutlet UILabel *buninessLabel;
  14. @property (weak, nonatomic) IBOutlet UILabel *checkLabel;
  15. @property (weak, nonatomic) IBOutlet UIImageView *firstImgVi;
  16. @property (weak, nonatomic) IBOutlet UIImageView *secondImgVi;
  17. @property (weak, nonatomic) IBOutlet UIImageView *lastImgVi;
  18. @property (weak, nonatomic) IBOutlet UILabel *authorLab;
  19. @property (weak, nonatomic) IBOutlet UILabel *refereeLab;
  20. @property (weak, nonatomic) IBOutlet UIImageView *eyeImgV;
  21. @property (weak, nonatomic) IBOutlet NSLayoutConstraint *rconst;
  22. @property (weak, nonatomic) IBOutlet NSLayoutConstraint *bconst;
  23. @end
  24. @implementation HomeTableViewCell
  25. - (void)awakeFromNib {
  26. [super awakeFromNib];
  27. }
  28. + (instancetype)cellWithTableView:(UITableView *)tableView AndIndex:(NSInteger)index {
  29. NSLog(@"============================数组index%ld",(long)index);
  30. NSString *ID = @"HomeTableViewCell1";
  31. switch (index) {
  32. case 1:
  33. ID = @"HomeTableViewCell1";
  34. break;
  35. case 2:
  36. ID = @"HomeTableViewCell2";
  37. break;
  38. default:
  39. ID = @"HomeTableViewCell3";
  40. break;
  41. }
  42. HomeTableViewCell *cell = (HomeTableViewCell *)[tableView dequeueReusableCellWithIdentifier:ID];
  43. if (cell == nil || !cell) {
  44. cell = [[[NSBundle mainBundle] loadNibNamed:@"HomeTableViewCell" owner:self options:nil] objectAtIndex:(index - 1)];
  45. }
  46. cell.selectionStyle = UITableViewCellSelectionStyleNone;
  47. return cell;
  48. }
  49. - (IBAction)deleteButtonClicked:(TDButton *)sender {
  50. if (self.buttonBlock) {
  51. self.buttonBlock();
  52. }
  53. }
  54. - (void)loadCurrentItemModel:(Item *)model{
  55. if (ISEmptyString(model.Title)) {
  56. _titleLabel.hidden = YES;
  57. }else{
  58. _titleLabel.attributedText = [self setTitleStr:model.Title isTop:model.IsTop];
  59. _titleLabel.lineBreakMode = NSLineBreakByTruncatingTail;
  60. }
  61. if (ISEmptyString(model.Source)) {
  62. self.bconst.constant = 0;
  63. _buninessLabel.hidden = YES;
  64. [self.eyeImgV mas_updateConstraints:^(MASConstraintMaker *make) {
  65. make.left.mas_equalTo(self.titleLabel);
  66. }];
  67. }else{
  68. _buninessLabel.text = model.Source;
  69. }
  70. _checkLabel.text = [NSString stringWithFormat:@"%ld", (long)model.ReadCount];
  71. if (!ISEmptyNumber(model.Author)) {
  72. _authorLab.hidden = NO;
  73. _authorLab.text = model.Author;
  74. } else {
  75. _authorLab.hidden = YES;
  76. self.rconst.constant = 0;
  77. [self.refereeLab mas_updateConstraints:^(MASConstraintMaker *make) {
  78. make.left.mas_equalTo(self.titleLabel);
  79. }];
  80. }
  81. _refereeLab.hidden = YES;
  82. if (model.ImageUrls.count >= 3) {
  83. if ([self isGifOrSwf:model.ImageUrls.firstObject]) {
  84. FLAnimatedImage * image = [FLAnimatedImage animatedImageWithGIFData:[NSData dataWithContentsOfURL:[NSURL URLWithString:model.ImageUrls.firstObject]]];
  85. FLAnimatedImageView * imageV = [[FLAnimatedImageView alloc] init];
  86. imageV.animatedImage = image;
  87. self.firstImgVi = imageV;
  88. }else{
  89. [self.firstImgVi setImageWithURL:[NSURL URLWithString:model.ImageUrls.firstObject] placeholder:IMG(@"img_placeHolder")];
  90. }
  91. if ([self isGifOrSwf:model.ImageUrls[1]]) {
  92. FLAnimatedImage * image = [FLAnimatedImage animatedImageWithGIFData:[NSData dataWithContentsOfURL:[NSURL URLWithString:model.ImageUrls[1]]]];
  93. FLAnimatedImageView * imageV = [[FLAnimatedImageView alloc] init];
  94. imageV.animatedImage = image;
  95. self.secondImgVi = imageV;
  96. }else{
  97. [self.secondImgVi setImageWithURL:[NSURL URLWithString:model.ImageUrls[1]] placeholder:IMG(@"img_placeHolder")];
  98. }
  99. if ([self isGifOrSwf:model.ImageUrls[2]]) {
  100. FLAnimatedImage * image = [FLAnimatedImage animatedImageWithGIFData:[NSData dataWithContentsOfURL:[NSURL URLWithString:model.ImageUrls[2]]]];
  101. FLAnimatedImageView * imageV = [[FLAnimatedImageView alloc] init];
  102. imageV.animatedImage = image;
  103. self.lastImgVi = imageV;
  104. }else{
  105. [self.lastImgVi setImageWithURL:[NSURL URLWithString:model.ImageUrls[2]] placeholder:IMG(@"img_placeHolder")];
  106. }
  107. // [self.secondImgVi setImageWithURL:[NSURL URLWithString:model.ImageUrls[1]] placeholder:IMG(@"img_placeHolder")];
  108. // [self.lastImgVi setImageWithURL:[NSURL URLWithString:model.ImageUrls[2]] placeholder:IMG(@"img_placeHolder")];
  109. self.firstImgVi.hidden = NO;
  110. self.lastImgVi.hidden = NO;
  111. self.secondImgVi.hidden = NO;
  112. }
  113. // else if (model.ImageUrls.count == 2) {
  114. // NSLog(@"%@",model.ImageUrls);
  115. // if ([model.ImageUrls.firstObject containsString:@"webp"]) {
  116. // [self.firstImgVi setImageWithURL:[NSURL URLWithString:model.ImageUrls.firstObject] placeholder:IMG(@"img_placeHolder")];
  117. // }else{
  118. // [self.firstImgVi sd_setImageWithURL: [NSURL URLWithString:model.ImageUrls.firstObject] placeholderImage:IMG(@"img_placeHolder")];
  119. // }
  120. //
  121. // [self.secondImgVi setImageWithURL:[NSURL URLWithString:model.ImageUrls[1]] placeholder:IMG(@"img_placeHolder")];
  122. // self.firstImgVi.hidden = NO;
  123. // self.lastImgVi.hidden = YES;
  124. // self.secondImgVi.hidden = NO;
  125. // }
  126. else{
  127. if ([self isGifOrSwf:model.ImageUrls.firstObject]) {
  128. FLAnimatedImage * image = [FLAnimatedImage animatedImageWithGIFData:[NSData dataWithContentsOfURL:[NSURL URLWithString:model.ImageUrls.firstObject]]];
  129. FLAnimatedImageView * imageV = [[FLAnimatedImageView alloc] init];
  130. imageV.animatedImage = image;
  131. self.firstImgVi = imageV;
  132. }else{
  133. [self.firstImgVi setImageWithURL:[NSURL URLWithString:model.ImageUrls.firstObject] placeholder:IMG(@"img_placeHolder")];
  134. }
  135. // [self.firstImgVi setImageWithURL:[NSURL URLWithString:model.ImageUrls.firstObject] placeholder:IMG(@"img_placeHolder")];
  136. self.firstImgVi.hidden = NO;
  137. self.lastImgVi.hidden = YES;
  138. self.secondImgVi.hidden = YES;
  139. }
  140. }
  141. - (NSMutableAttributedString *)setTitleStr:(NSString *)text isTop:(BOOL)isTop
  142. {
  143. NSMutableAttributedString * mattStr = [[NSMutableAttributedString alloc] init];
  144. // [mattStr addAttributes:@{NSFontAttributeName: [UIFont fontWithName:@"PingFang-SC-Regular" size:18],NSForegroundColorAttributeName: UIColorHex(000000)} range:NSMakeRange(0, text.length)];
  145. // NSMutableParagraphStyle *style = [[NSMutableParagraphStyle alloc]init];
  146. // 行间距
  147. // [style setLineSpacing:8];
  148. // // 段落间距
  149. // [style setParagraphSpacing:6];
  150. // // 首行缩进
  151. // [style setFirstLineHeadIndent:25];
  152. // [mattStr addAttribute:NSParagraphStyleAttributeName value:style range:NSMakeRange(0, text.length)];
  153. if (isTop) {
  154. NSTextAttachment *imageAtta = [[NSTextAttachment alloc] init];
  155. imageAtta.bounds = CGRectMake(0, -2, 32, 15.5);
  156. imageAtta.image = [UIImage imageNamed:@"homeicon_setTop"];
  157. NSAttributedString *attach = [NSAttributedString attributedStringWithAttachment:imageAtta];
  158. [mattStr insertAttributedString:attach atIndex:0];
  159. [mattStr appendAttributedString:[[NSAttributedString alloc] initWithString:@" "]];
  160. [mattStr appendAttributedString:[[NSAttributedString alloc] initWithString:text]];
  161. }else{
  162. [mattStr appendAttributedString:[[NSAttributedString alloc] initWithString:text]];
  163. }
  164. return mattStr;
  165. }
  166. - (BOOL)isGifOrSwf:(NSString *)imageStr
  167. {
  168. NSString * name = [[imageStr pathExtension] lowercaseString];
  169. if ([name hasSuffix:@"gif"] || [name hasSuffix:@"swf"]) {
  170. return YES;
  171. }else{
  172. return NO;
  173. }
  174. }
  175. @end