OneImageCell.m 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  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. // [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. NSString *url = [model.iteminfo[0] objectForKey:@"url"];
  88. [self.oneImage sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@%@",imageURl,url]] placeholderImage:[UIImage imageNamed:@"jiazai"]];
  89. NSLog(@"date = %@",[Helper sharedAccount].date);
  90. UITapGestureRecognizer *Tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(toImage:)];;
  91. [self.oneImage addGestureRecognizer:Tap];
  92. self.oneImage.userInteractionEnabled = YES;
  93. // if([[Helper sharedAccount].date isEqualToString:date2]){
  94. // self.Day.hidden = YES;
  95. // self.Month.hidden = YES;
  96. // }
  97. // [Helper sharedAccount].date = date2;
  98. if ([model.isditto isEqualToString:@"1"]) {
  99. self.Day.hidden = YES;
  100. self.Month.hidden = YES;
  101. }
  102. }
  103. - (void)toImage:(UITapGestureRecognizer*)recognizer {
  104. [self.delegate clickImage:_model andNum:0];
  105. }
  106. #pragma mark - labelOne SizeToFitHeight
  107. - (void)buildLabelOne
  108. {
  109. self.detailLabel.text = _model.intro;
  110. _detailLabel.font = [UIFont systemFontOfSize:15];
  111. _detailLabel.numberOfLines = 0;
  112. CGFloat height = [UILabel getHeightByWidth:_detailLabel.frame.size.width title:_detailLabel.text font:_detailLabel.font];
  113. if (height>80) {
  114. height = 80;
  115. }
  116. _detailLabel.frame = CGRectMake(210, 15, 135, height);
  117. }
  118. - (void)setSelected:(BOOL)selected animated:(BOOL)animated {
  119. [super setSelected:selected animated:animated];
  120. // Configure the view for the selected state
  121. }
  122. @end