123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249 |
- //
- // KBCommunityCell.m
- // YouHuiProject
- //
- // Created by 小花 on 2018/5/16.
- // Copyright © 2018年 kuxuan. All rights reserved.
- //
- #import "KBCommunityCell.h"
- #import "UIView+SDAutoLayout.h"
- #import "KBCommunityDetailModel.h"
- #import "CCCopyLabel.h"
- @interface KBCommunityCell ()
- @property (nonatomic, strong) UIView *backView;
- @property (nonatomic, strong) UIImageView *iconView;
- @property (nonatomic, strong) UILabel *userName;
- @property (nonatomic, strong) UILabel *timeLabel;
- @property (nonatomic, strong) CCCopyLabel *contentLabel;
- @property (nonatomic, strong) UIView *bottomLine;
- @property (nonatomic, strong) UIButton *oneTouchShareButton;
- @end
- @implementation KBCommunityCell
- + (instancetype)cellWithTableView:(UITableView *)tableView {
- static NSString *cellID = nil;
- cellID = NSStringFromClass([self class]);
- KBCommunityCell *cell = [tableView dequeueReusableCellWithIdentifier:cellID];
- if (!cell) {
- cell = [[KBCommunityCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellID];
- cell.selectionStyle = UITableViewCellSelectionStyleNone;
- cell.backgroundColor=[UIColor yhGrayColor];
- }
- return cell;
-
- }
- - (void)awakeFromNib {
- [super awakeFromNib];
- // Initialization code
- }
- - (void)setSelected:(BOOL)selected animated:(BOOL)animated {
- [super setSelected:selected animated:animated];
- // Configure the view for the selected state
- }
- - (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
- self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
- if (self) {
- [self initSubViews];
- }
- return self;
- }
- - (void)initSubViews {
- [self.contentView addSubview:self.backView];
- [self.backView addSubview:self.iconView];
- [self.backView addSubview:self.userName];
- [self.backView addSubview:self.timeLabel];
- [self.backView addSubview:self.contentLabel];
- [self.backView addSubview:self.picContainerView];
- [self.contentView addSubview:self.bottomLine];
- // [self.contentView addSubview:self.oneTouchShareButton];
- [self.backView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.mas_equalTo(FITSIZE(10));
- make.right.mas_equalTo(-FITSIZE(10));
- make.top.mas_equalTo(5);
- make.bottom.mas_equalTo(0);
- }];
- [self.iconView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.mas_equalTo(10);
- make.top.mas_equalTo(14);
- make.width.height.mas_equalTo(40);
- }];
-
- [self.userName mas_makeConstraints:^(MASConstraintMaker *make) {
- make.top.mas_equalTo(16);
- make.left.mas_equalTo(self.iconView.mas_right).mas_offset(10);
- }];
-
- [self.timeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
- make.bottom.equalTo(self.iconView.mas_bottom);
- make.left.mas_equalTo(self.iconView.mas_right).mas_offset(10);
- }];
-
- [self.contentLabel mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.mas_equalTo(10);
- make.right.mas_equalTo(-10);
- make.top.mas_equalTo(self.iconView.mas_bottom).mas_offset(10);
- }];
-
- [self.picContainerView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.mas_equalTo(10);
- make.right.mas_equalTo(-10);
- make.top.mas_equalTo(self.contentLabel.mas_bottom).mas_offset(10);
- }];
-
- [self.bottomLine mas_makeConstraints:^(MASConstraintMaker *make) {
- make.top.mas_equalTo(self.picContainerView.mas_bottom).mas_offset(10);
- make.left.right.mas_equalTo(0);
- make.height.mas_equalTo(5);
- }];
-
- // [self.oneTouchShareButton mas_makeConstraints:^(MASConstraintMaker *make) {
- // make.right.mas_equalTo((FITSIZE(-20)));
- // make.top.mas_equalTo(0);
- // make.width.mas_equalTo(82);
- // make.height.mas_equalTo(60);
- // }];
-
- [self setupAutoHeightWithBottomView:self.bottomLine bottomMargin:0];
- }
- - (void)setModel:(KBCommunityModel *)model {
- _model = model;
- // 时间分享
- self.userName.text = model.name;
- self.contentLabel.text = model.note;
- if (model.img &&![@"" isEqualToString:model.img] && model.img.length>5) {
- [self.iconView sd_setImageWithURL:[NSURL URLWithString:model.img] placeholderImage:[UIImage imageNamed:@"login"]];
- }else{
- [self.iconView setImage:[UIImage imageNamed:@"login"]];
- }
- //时间
- NSTimeInterval interval =[model.update_time doubleValue];
- NSDate *date=[NSDate dateWithTimeIntervalSince1970:interval];
- NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
- [formatter setDateFormat:@"MM-dd HH:mm"];
- NSString *dateString = [formatter stringFromDate: date];
- self.timeLabel.text=[NSString stringWithFormat:@"%@",dateString];
-
-
- NSMutableArray *arr=[NSMutableArray array];
- NSMutableArray *modelArr=[NSMutableArray array];
- if (model.detail.count>0) {
- for (int i=0; i<(model.detail.count<9?model.detail.count:9); i++) {
- KBCommunityDetailModel *detailModel=model.detail[i];
- [arr addObject:detailModel.img];
- [modelArr addObject:detailModel];
- }
- self.picContainerView.contentWidth=[UIScreen mainScreen].bounds.size.width-FITSIZE(20);
- self.picContainerView.picPathStringsArray = arr;
- self.picContainerView.modelArray=modelArr;
- }else{
- self.picContainerView.picPathStringsArray=@[];
- self.picContainerView.modelArray=@[];
- }
- CGFloat top = self.picContainerView.picPathStringsArray.count>0 ? 10:0;
- [self.picContainerView mas_updateConstraints:^(MASConstraintMaker *make) {
- make.top.mas_equalTo(self.contentLabel.mas_bottom).mas_offset(top);
- make.height.mas_equalTo(self.picContainerView.fixedHeight);
- }];
- }
- #pragma mark -事件
- -(void)oneTouchShareAction{
- if (self.delegate && [self.delegate respondsToSelector:@selector(oneTouchShareWithModel:)]) {
- [self.delegate oneTouchShareWithModel:self.model];
- }
- }
- #pragma mark ---- layzer ----
- - (UIImageView *)iconView {
- if (!_iconView) {
- _iconView = [[UIImageView alloc] init];
- _iconView.backgroundColor = [UIColor yhGrayColor];
- _iconView.layer.cornerRadius = 20;
- _iconView.layer.masksToBounds = YES;
-
- }
- return _iconView;
- }
- - (UILabel *)userName {
- if (!_userName) {
- _userName = [[UILabel alloc] init];
- _userName.textColor = [UIColor YHColorWithHex:0x333333];
- _userName.font = [UIFont systemFontOfSize:15];
- }
- return _userName;
- }
- - (UILabel *)timeLabel {
- if (!_timeLabel) {
- _timeLabel = [[UILabel alloc] init];
- _timeLabel.font = [UIFont systemFontOfSize:12];
- _timeLabel.textColor = [UIColor YHColorWithHex:0x999999];
- _timeLabel.text=@"a";
- }
- return _timeLabel;
- }
- - (UILabel *)contentLabel {
- if (!_contentLabel) {
- _contentLabel = [[CCCopyLabel alloc] init];
- _contentLabel.textColor = [UIColor YHColorWithHex:0x555555];
- _contentLabel.font = [UIFont systemFontOfSize:16];
- _contentLabel.numberOfLines = 0;
- }
- return _contentLabel;
- }
- - (PhotoContainerView *)picContainerView {
- if (!_picContainerView) {
- _picContainerView = [PhotoContainerView new];
- }
- return _picContainerView;
- }
- - (UIView *)bottomLine {
- if (!_bottomLine) {
- _bottomLine = [[UIView alloc] init];
- _bottomLine.hidden=YES;
- _bottomLine.backgroundColor = [UIColor yhGrayColor];
- }
- return _bottomLine;
- }
- -(UIButton *)oneTouchShareButton{
- if (!_oneTouchShareButton) {
- _oneTouchShareButton=[UIButton buttonWithType:UIButtonTypeCustom];
- [_oneTouchShareButton setImage:[UIImage imageNamed:@"oneTouchShare"] forState:UIControlStateNormal];
- [_oneTouchShareButton addTarget:self action:@selector(oneTouchShareAction) forControlEvents:UIControlEventTouchUpInside];
- }
- return _oneTouchShareButton;
- }
- -(UIView *)backView{
- if (!_backView) {
- _backView=[[UIView alloc]init];
- _backView.backgroundColor=[UIColor whiteColor];
- _backView.layer.cornerRadius = 5;
- // _backView.layer.shadowColor = [UIColor YHColorWithHex:0x000000].CGColor;
- // _backView.layer.shadowOffset = CGSizeMake(0,0);
- // _backView.layer.shadowOpacity = 0.2;
- // _backView.layer.shadowRadius = 5;
- }
- return _backView;
- }
- @end
|