口袋优选

KBCommunityCell.m 8.4KB

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