123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161 |
- //
- // FKCircleCommentCell.m
- // FirstLink
- //
- // Created by jack on 16/6/15.
- // Copyright © 2016年 FirstLink. All rights reserved.
- //
- #import "FKCirDetailCommentCell.h"
- #import "FKCircleDetailViewModel.h"
- #import "FKCirAllCommentViewModel.h"
- @interface FKCirDetailCommentCell ()
- @property (nonatomic, strong) UIImageView *iconImgView;
- @property (nonatomic, strong) UIView *bottomLine;
- @property (nonatomic, strong) UILabel *nameLabel;
- @property (nonatomic, strong) UILabel *timeLabel;
- @property (nonatomic, strong) UILabel *commentLabel;
- @end
- @implementation FKCirDetailCommentCell
- - (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
- if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
-
- [self addAllSubviews];
- self.selectionStyle = UITableViewCellSelectionStyleNone;
- self.contentView.backgroundColor = [UIColor whiteColor];
- }
- return self;
- }
- - (void)addAllSubviews{
-
- [self.contentView addSubview:self.iconImgView];
- [self.contentView addSubview:self.nameLabel];
- [self.contentView addSubview:self.timeLabel];
- [self.contentView addSubview:self.commentLabel];
- [self.contentView addSubview:self.bottomLine];
-
- [self.iconImgView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.equalTo(self.contentView).offset(15);
- make.top.equalTo(self.contentView).offset(10);
- make.width.height.mas_equalTo(30);
- }];
-
- [self.nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
- make.centerY.equalTo(self.iconImgView);
- make.left.equalTo(self.iconImgView.mas_right).offset(16);
- }];
-
- [self.timeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
- make.right.equalTo(self.contentView).offset(- 15);
- make.centerY.equalTo(self.nameLabel);
- }];
-
- [self.commentLabel mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.equalTo(self.nameLabel);
- make.top.equalTo(self.nameLabel.mas_bottom).offset(8);
- make.right.equalTo(self.contentView).offset(- 15);
- }];
-
- [self.bottomLine mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.equalTo(self.commentLabel);
- make.right.bottom.equalTo(self.contentView);
- make.height.equalTo(@0.5);
- }];
- }
- - (void)fk_configWithViewModel:(id)viewModel indexPath:(NSIndexPath *)indexPath{
- if ([viewModel isKindOfClass:[FKCircleDetailViewModel class]]) {
- FKCircleDetailViewModel *cirViewModel = (FKCircleDetailViewModel *)viewModel;
- FKCircleCommentItem *commentItem = [cirViewModel.dataItem commentItemAtIndex:indexPath.row];
- if (commentItem){
- [self.iconImgView setImageWithURL:commentItem.headPicUrl cdnWidth:60];
- self.nameLabel.attributedText = [commentItem getRealCommentTitle];
- self.commentLabel.text = commentItem.content;
- self.timeLabel.text = [FLStringHelper convertToCommonFormateFromString:commentItem.createTime baseTime:cirViewModel.dataItem.serveTime];
- }
- }
-
- if ([viewModel isKindOfClass:[FKCirAllCommentViewModel class]]){
- FKCirAllCommentViewModel *commentViewModel = (FKCirAllCommentViewModel *)viewModel;
- FKCircleCommentItem *commentItem = [commentViewModel commentItemAtIndex:indexPath.row];
- if (commentItem){
- [self.iconImgView setImageWithURL:commentItem.headPicUrl cdnWidth:60];
- self.nameLabel.attributedText = [commentItem getRealCommentTitle];
- self.commentLabel.text = commentItem.content;
- self.timeLabel.text = [FLStringHelper convertToCommonFormateFromString:commentItem.createTime baseTime:commentViewModel.serveTime];
- }
- }
- }
- + (CGFloat)cellHeightForCommentText:(NSString *)text{
-
- CGRect rect = [FLStringHelper rectOfString:text
- font:[UIFont systemFontOfSize:14]
- width:UISCREENWIDTH - 76];
- CGFloat otherHeight = 52;
- if (rect.size.height == 0) return otherHeight;
- return rect.size.height + otherHeight;
- }
- #pragma mark - property
- - (UIImageView *)iconImgView{
- if (_iconImgView == nil) {
- _iconImgView = [[UIImageView alloc]init];
- _iconImgView.layer.cornerRadius = 15;
- _iconImgView.layer.masksToBounds = YES;
- }
- return _iconImgView;
- }
- - (UILabel *)nameLabel{
- if (_nameLabel == nil) {
- _nameLabel = [[UILabel alloc]init];
- _nameLabel.backgroundColor = [UIColor clearColor];
- _nameLabel.font = [UIFont systemFontOfSize:14];
- _nameLabel.textColor = UIColorFromRGB(0x333333);
- _nameLabel.textAlignment = NSTextAlignmentLeft;
- }
- return _nameLabel;
- }
- - (UILabel *)timeLabel{
- if (_timeLabel == nil) {
- _timeLabel = [[UILabel alloc]init];
- _timeLabel.backgroundColor = [UIColor clearColor];
- _timeLabel.font = [UIFont systemFontOfSize:14];
- _timeLabel.textColor = UIColorFromRGB(0x999999);
- _timeLabel.textAlignment = NSTextAlignmentRight;
- }
- return _timeLabel;
- }
- - (UILabel *)commentLabel{
- if (_commentLabel == nil) {
- _commentLabel = [[UILabel alloc]init];
- _commentLabel.backgroundColor = [UIColor clearColor];
- _commentLabel.font = [UIFont systemFontOfSize:14];
- _commentLabel.textColor = UIColorFromRGB(0x999999);
- _commentLabel.numberOfLines = 0;
- }
- return _commentLabel;
- }
- - (UIView *)bottomLine{
- if (_bottomLine == nil) {
- _bottomLine = [[UIView alloc]init];
- _bottomLine.backgroundColor = UIColorFromRGB(0xf4f4f4);
- }
- return _bottomLine;
- }
- @end
|