TwoImageCell.m 4.8 KB

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