FourImageCell.m 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  1. //
  2. // FourImageCell.m
  3. // 千模
  4. //
  5. // Created by MUMEI on 2018/6/7.
  6. // Copyright © 2018年 MUMEI. All rights reserved.
  7. //
  8. #import "FourImageCell.h"
  9. @implementation FourImageCell
  10. - (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
  11. {
  12. self = [super initWithStyle:style reuseIdentifier:reuseIdentifier ];
  13. if (self) {
  14. // 初始化子视图
  15. [self buildLabelOne];
  16. }
  17. return self;
  18. }
  19. - (void)awakeFromNib {
  20. [super awakeFromNib];
  21. [self buildLabelOne];
  22. // Initialization code
  23. }
  24. - (void)setNum:(int)num{
  25. if(num==3){
  26. self.image4.hidden = YES;
  27. }
  28. }
  29. - (void)setModel:(PrivateModel *)model{
  30. _model = model;
  31. self.detailLabel.text = model.intro;
  32. [self buildLabelOne];
  33. NSString *now = [Helper getCurrentTimes];
  34. NSString *lastDay = [Helper getLastTimes];
  35. NSArray * dateNow = [now componentsSeparatedByString:@" "];
  36. NSArray * nowYMD = [dateNow[0] componentsSeparatedByString:@"-"];
  37. NSString * nowY = nowYMD[0];
  38. NSString * nowM = nowYMD[1];
  39. NSString * nowD = nowYMD[2];
  40. NSArray * dateLast = [lastDay componentsSeparatedByString:@" "];
  41. NSArray * lastYMD = [dateLast[0] componentsSeparatedByString:@"-"];
  42. NSString * lastY = lastYMD[0];
  43. NSString * lastM = lastYMD[1];
  44. NSString * lastD = lastYMD[2];
  45. NSArray * date = [model.pdate componentsSeparatedByString:@" "];
  46. NSString * date2 = date[0];
  47. NSArray * YMD = [date2 componentsSeparatedByString:@"-"];
  48. NSString * Y = YMD[0];
  49. NSString * M = YMD[1];
  50. NSString * D = YMD[2];
  51. if ([Y isEqualToString:nowY]) {
  52. if ([M isEqualToString:nowM]) {
  53. if ([D isEqualToString:nowD]) {
  54. D = @"今天";
  55. self.Day.text = @"";
  56. self.Mounth.hidden = YES;
  57. self.noMonth = YES;
  58. }
  59. }
  60. }
  61. if ([Y isEqualToString:lastY]) {
  62. if ([M isEqualToString:lastM]) {
  63. if ([D isEqualToString:lastD]) {
  64. D = @"昨天";
  65. self.Day.text = D;
  66. self.Mounth.hidden = YES;
  67. self.noMonth = YES;
  68. }
  69. }
  70. }
  71. if (!self.noMonth) {
  72. if([M isEqualToString:@"01"]){
  73. M = @"1";
  74. }else if ([M isEqualToString:@"02"]){
  75. M = @"2";
  76. }else if ([M isEqualToString:@"03"]){
  77. M = @"3";
  78. }else if ([M isEqualToString:@"04"]){
  79. M = @"4";
  80. }else if ([M isEqualToString:@"05"]){
  81. M = @"5";
  82. }else if ([M isEqualToString:@"06"]){
  83. M = @"6";
  84. }else if ([M isEqualToString:@"07"]){
  85. M = @"7";
  86. }else if ([M isEqualToString:@"08"]){
  87. M = @"8";
  88. }else if ([M isEqualToString:@"09"]){
  89. M = @"9";
  90. }else if ([M isEqualToString:@"10"]){
  91. M = @"10";
  92. }else if ([M isEqualToString:@"11"]){
  93. M = @"11";
  94. }else if ([M isEqualToString:@"12"]){
  95. M = @"12";
  96. }
  97. self.Day.text = D;
  98. self.Mounth.text = [NSString stringWithFormat:@"%@月",M];
  99. }
  100. for (int i=0; i<model.iteminfo.count; i++) {
  101. NSString *url = [model.iteminfo[i] objectForKey:@"url"];
  102. if (i==0) {
  103. [self.image1 sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@%@",imageURl,url]] placeholderImage:[UIImage imageNamed:@"jiazai"]];
  104. }else if (i==1){
  105. [self.image2 sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@%@",imageURl,url]] placeholderImage:[UIImage imageNamed:@"jiazai"]];
  106. }else if (i==2){
  107. [self.image3 sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@%@",imageURl,url]] placeholderImage:[UIImage imageNamed:@"jiazai"]];
  108. }else if (i==3){
  109. [self.image4 sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@%@",imageURl,url]] placeholderImage:[UIImage imageNamed:@"jiazai"]];
  110. }
  111. }
  112. NSLog(@"date = %@",[Helper sharedAccount].date);
  113. UITapGestureRecognizer *Tap1 = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(toImage1:)];;
  114. [self.image1 addGestureRecognizer:Tap1];
  115. self.image1.userInteractionEnabled = YES;
  116. UITapGestureRecognizer *Tap2 = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(toImage2:)];;
  117. [self.image2 addGestureRecognizer:Tap2];
  118. self.image2.userInteractionEnabled = YES;
  119. UITapGestureRecognizer *Tap3 = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(toImage3:)];;
  120. [self.image3 addGestureRecognizer:Tap3];
  121. self.image3.userInteractionEnabled = YES;
  122. UITapGestureRecognizer *Tap4 = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(toImage4:)];;
  123. [self.image4 addGestureRecognizer:Tap4];
  124. self.image4.userInteractionEnabled = YES;
  125. // if([[Helper sharedAccount].date isEqualToString:date2]){
  126. // self.Day.hidden = YES;
  127. // self.Mounth.hidden = YES;
  128. // }
  129. // [Helper sharedAccount].date = date2;
  130. if ([model.isditto isEqualToString:@"1"]) {
  131. self.Day.hidden = YES;
  132. self.Mounth.hidden = YES;
  133. }
  134. }
  135. - (void)toImage1:(UITapGestureRecognizer*)recognizer {
  136. [self.delegate clickImage:_model andNum:0];
  137. }
  138. - (void)toImage2:(UITapGestureRecognizer*)recognizer {
  139. [self.delegate clickImage:_model andNum:1];
  140. }
  141. - (void)toImage3:(UITapGestureRecognizer*)recognizer {
  142. [self.delegate clickImage:_model andNum:2];
  143. }
  144. - (void)toImage4:(UITapGestureRecognizer*)recognizer {
  145. [self.delegate clickImage:_model andNum:3];
  146. }
  147. #pragma mark - labelOne SizeToFitHeight
  148. - (void)buildLabelOne
  149. {
  150. self.detailLabel.text = _model.intro;
  151. _detailLabel.font = [UIFont systemFontOfSize:15];
  152. _detailLabel.numberOfLines = 0;
  153. CGFloat height = [UILabel getHeightByWidth:_detailLabel.frame.size.width title:_detailLabel.text font:_detailLabel.font];
  154. if (height>80) {
  155. height = 80;
  156. }
  157. _detailLabel.frame = CGRectMake(210, 15, 135, height);
  158. }
  159. - (void)setSelected:(BOOL)selected animated:(BOOL)animated {
  160. [super setSelected:selected animated:animated];
  161. // Configure the view for the selected state
  162. }
  163. @end