OneImageCell.m 4.2 KB

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