天天省钱快报

KBCommunityCell.m 7.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  1. //
  2. // KBCommunityCell.m
  3. // YouHuiProject
  4. //
  5. // Created by 小花 on 2018/5/16.
  6. // Copyright © 2018年 kuxuan. All rights reserved.
  7. //
  8. #import "KBCommunityCell.h"
  9. #import "UIView+SDAutoLayout.h"
  10. #import "KBCommunityDetailModel.h"
  11. #import "CCCopyLabel.h"
  12. @interface KBCommunityCell ()
  13. @property (nonatomic, strong) UIImageView *iconView;
  14. @property (nonatomic, strong) UILabel *userName;
  15. @property (nonatomic, strong) UILabel *timeLabel;
  16. @property (nonatomic, strong) CCCopyLabel *contentLabel;
  17. @property (nonatomic, strong) UIView *bottomLine;
  18. @property (nonatomic, strong) UIButton *oneTouchShareButton;
  19. @end
  20. @implementation KBCommunityCell
  21. + (instancetype)cellWithTableView:(UITableView *)tableView {
  22. static NSString *cellID = nil;
  23. cellID = NSStringFromClass([self class]);
  24. KBCommunityCell *cell = [tableView dequeueReusableCellWithIdentifier:cellID];
  25. if (!cell) {
  26. cell = [[KBCommunityCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellID];
  27. cell.selectionStyle = UITableViewCellSelectionStyleNone;
  28. }
  29. return cell;
  30. }
  31. - (void)awakeFromNib {
  32. [super awakeFromNib];
  33. // Initialization code
  34. }
  35. - (void)setSelected:(BOOL)selected animated:(BOOL)animated {
  36. [super setSelected:selected animated:animated];
  37. // Configure the view for the selected state
  38. }
  39. - (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
  40. self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
  41. if (self) {
  42. [self initSubViews];
  43. }
  44. return self;
  45. }
  46. - (void)initSubViews {
  47. [self.contentView addSubview:self.iconView];
  48. [self.contentView addSubview:self.userName];
  49. [self.contentView addSubview:self.timeLabel];
  50. [self.contentView addSubview:self.contentLabel];
  51. [self.contentView addSubview:self.picContainerView];
  52. [self.contentView addSubview:self.bottomLine];
  53. // [self.contentView addSubview:self.oneTouchShareButton];
  54. [self.iconView mas_makeConstraints:^(MASConstraintMaker *make) {
  55. make.left.mas_equalTo(10);
  56. make.top.mas_equalTo(14);
  57. make.width.height.mas_equalTo(40);
  58. }];
  59. [self.userName mas_makeConstraints:^(MASConstraintMaker *make) {
  60. make.top.mas_equalTo(16);
  61. make.left.mas_equalTo(self.iconView.mas_right).mas_offset(10);
  62. }];
  63. [self.timeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  64. make.bottom.equalTo(self.iconView.mas_bottom);
  65. make.left.mas_equalTo(self.iconView.mas_right).mas_offset(10);
  66. }];
  67. [self.contentLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  68. make.left.mas_equalTo(10);
  69. make.right.mas_equalTo(-10);
  70. make.top.mas_equalTo(self.iconView.mas_bottom).mas_offset(10);
  71. }];
  72. [self.picContainerView mas_makeConstraints:^(MASConstraintMaker *make) {
  73. make.left.mas_equalTo(10);
  74. make.right.mas_equalTo(-10);
  75. make.top.mas_equalTo(self.contentLabel.mas_bottom).mas_offset(10);
  76. }];
  77. [self.bottomLine mas_makeConstraints:^(MASConstraintMaker *make) {
  78. make.top.mas_equalTo(self.picContainerView.mas_bottom).mas_offset(10);
  79. make.left.right.mas_equalTo(0);
  80. make.height.mas_equalTo(5);
  81. }];
  82. // [self.oneTouchShareButton mas_makeConstraints:^(MASConstraintMaker *make) {
  83. // make.right.mas_equalTo((FITSIZE(-20)));
  84. // make.top.mas_equalTo(0);
  85. // make.width.mas_equalTo(82);
  86. // make.height.mas_equalTo(60);
  87. // }];
  88. [self setupAutoHeightWithBottomView:self.bottomLine bottomMargin:0];
  89. }
  90. - (void)setModel:(KBCommunityModel *)model {
  91. _model = model;
  92. // 时间分享
  93. self.userName.text = model.name;
  94. self.contentLabel.text = model.note;
  95. if (model.img &&![@"" isEqualToString:model.img] && model.img.length>5) {
  96. [self.iconView sd_setImageWithURL:[NSURL URLWithString:model.img] placeholderImage:[UIImage imageNamed:@"login"]];
  97. }else{
  98. [self.iconView setImage:[UIImage imageNamed:@"login"]];
  99. }
  100. //时间
  101. NSTimeInterval interval =[model.update_time doubleValue];
  102. NSDate *date=[NSDate dateWithTimeIntervalSince1970:interval];
  103. NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
  104. [formatter setDateFormat:@"MM-dd HH:mm"];
  105. NSString *dateString = [formatter stringFromDate: date];
  106. self.timeLabel.text=[NSString stringWithFormat:@"%@",dateString];
  107. NSMutableArray *arr=[NSMutableArray array];
  108. NSMutableArray *modelArr=[NSMutableArray array];
  109. if (model.detail.count>0) {
  110. for (int i=0; i<(model.detail.count<9?model.detail.count:9); i++) {
  111. KBCommunityDetailModel *detailModel=model.detail[i];
  112. [arr addObject:detailModel.img];
  113. [modelArr addObject:detailModel];
  114. }
  115. self.picContainerView.picPathStringsArray = arr;
  116. self.picContainerView.modelArray=modelArr;
  117. }else{
  118. self.picContainerView.picPathStringsArray=@[];
  119. self.picContainerView.modelArray=@[];
  120. }
  121. CGFloat top = self.picContainerView.picPathStringsArray.count>0 ? 10:0;
  122. [self.picContainerView mas_updateConstraints:^(MASConstraintMaker *make) {
  123. make.top.mas_equalTo(self.contentLabel.mas_bottom).mas_offset(top);
  124. make.height.mas_equalTo(self.picContainerView.fixedHeight);
  125. }];
  126. }
  127. #pragma mark -事件
  128. -(void)oneTouchShareAction{
  129. if (self.delegate && [self.delegate respondsToSelector:@selector(oneTouchShareWithModel:)]) {
  130. [self.delegate oneTouchShareWithModel:self.model];
  131. }
  132. }
  133. #pragma mark ---- layzer ----
  134. - (UIImageView *)iconView {
  135. if (!_iconView) {
  136. _iconView = [[UIImageView alloc] init];
  137. _iconView.backgroundColor = [UIColor yhGrayColor];
  138. _iconView.layer.cornerRadius = 20;
  139. _iconView.layer.masksToBounds = YES;
  140. }
  141. return _iconView;
  142. }
  143. - (UILabel *)userName {
  144. if (!_userName) {
  145. _userName = [[UILabel alloc] init];
  146. _userName.textColor = [UIColor YHColorWithHex:0x333333];
  147. _userName.font = [UIFont systemFontOfSize:15];
  148. }
  149. return _userName;
  150. }
  151. - (UILabel *)timeLabel {
  152. if (!_timeLabel) {
  153. _timeLabel = [[UILabel alloc] init];
  154. _timeLabel.font = [UIFont systemFontOfSize:12];
  155. _timeLabel.textColor = [UIColor YHColorWithHex:0x999999];
  156. _timeLabel.text=@"a";
  157. }
  158. return _timeLabel;
  159. }
  160. - (UILabel *)contentLabel {
  161. if (!_contentLabel) {
  162. _contentLabel = [[CCCopyLabel alloc] init];
  163. _contentLabel.textColor = [UIColor YHColorWithHex:0x555555];
  164. _contentLabel.font = [UIFont systemFontOfSize:16];
  165. _contentLabel.numberOfLines = 0;
  166. }
  167. return _contentLabel;
  168. }
  169. - (PhotoContainerView *)picContainerView {
  170. if (!_picContainerView) {
  171. _picContainerView = [PhotoContainerView new];
  172. }
  173. return _picContainerView;
  174. }
  175. - (UIView *)bottomLine {
  176. if (!_bottomLine) {
  177. _bottomLine = [[UIView alloc] init];
  178. _bottomLine.backgroundColor = [UIColor yhGrayColor];
  179. }
  180. return _bottomLine;
  181. }
  182. -(UIButton *)oneTouchShareButton{
  183. if (!_oneTouchShareButton) {
  184. _oneTouchShareButton=[UIButton buttonWithType:UIButtonTypeCustom];
  185. [_oneTouchShareButton setImage:[UIImage imageNamed:@"oneTouchShare"] forState:UIControlStateNormal];
  186. [_oneTouchShareButton addTarget:self action:@selector(oneTouchShareAction) forControlEvents:UIControlEventTouchUpInside];
  187. }
  188. return _oneTouchShareButton;
  189. }
  190. @end