// // DetailTitleView.m // TheoryNetwork // // Created by tederen on 2019/9/26. // Copyright © 2019 tederen. All rights reserved. // #import "DetailTitleView.h" #import "DocumentModel.h" #import "ZYCTool.h" @interface DetailTitleView () @property (nonatomic, strong) UILabel *titleLabel; @property (nonatomic, strong) UILabel *timeLabel; /// 来源 : 新华出版社 @property (nonatomic, strong) UILabel *buninessLabel; @property (nonatomic, strong) UIView *verticalLine; @property (nonatomic, strong) UILabel *readLab; @property (nonatomic, strong) UIImageView *checkImgVi; @property (nonatomic, strong) UILabel *readNumLab; @property (nonatomic, strong) UILabel *authorLab; @property (nonatomic, strong) UILabel *refereeLab; @property (nonatomic, strong) UILabel *shoujianrenlab; @property (nonatomic, strong) UILabel *haveReadNumberlab; @property (nonatomic, strong) UILabel *noReadNumberlab; @property (nonatomic, strong) TDButton *noticButton; @property (nonatomic, strong) UIView *lineViewA; @property (nonatomic, strong) UIView *lineViewB; @property (nonatomic, strong) UIView *lineViewC; @end @implementation DetailTitleView - (instancetype)init { self = [super init]; if (self) { [self addSubview:self.titleLabel]; [self addSubview:self.timeLabel]; [self addSubview:self.buninessLabel]; [self addSubview:self.checkImgVi]; [self addSubview:self.readLab]; [self addSubview:self.readNumLab]; [self addSubview:self.authorLab]; [self addSubview:self.refereeLab]; [self addSubview:self.shoujianrenlab]; [self addSubview:self.haveReadNumberlab]; [self addSubview:self.noticButton]; [self addSubview:self.noReadNumberlab]; } return self; } - (void)loadTitleModel:(Item *)model { // CGFloat topMargin = 14.f; CGFloat leftMargin = 22.f; _titleLabel.text = model.Title; _titleLabel.textColor = [UIColor hexStringToColor:@"0A0A0A"]; _titleLabel.font = [UIFont systemFontOfSize:23.f]; [ZYCTool setLabelSpace:_titleLabel withSpace:10.f withFont:_titleLabel.font]; CGSize titleSize = [_titleLabel sizeThatFits:CGSizeMake(kGXScreenWidth-20*2, MAXFLOAT)]; _titleLabel.frame = CGRectMake(leftMargin, topMargin, titleSize.width, titleSize.height); topMargin += titleSize.height; topMargin += 21.f; [_authorLab mas_makeConstraints:^(MASConstraintMaker *make) { make.left.mas_equalTo(leftMargin); make.top.mas_equalTo(topMargin); make.width.mas_lessThanOrEqualTo(60); }]; if (!ISEmptyNumber(model.Author)) { _authorLab.text = model.Author; // 竖线 UIView *lineViewA = [UIView new]; lineViewA.backgroundColor = kColorFromRGB(0xe5e5e5); [self addSubview:lineViewA]; [lineViewA mas_makeConstraints:^(MASConstraintMaker *make) { make.left.equalTo(self.authorLab.mas_right).offset(12); make.top.equalTo(self.authorLab).offset(2); make.height.mas_equalTo(12.5); make.width.mas_equalTo(1); }]; self.lineViewA = lineViewA; } else { _authorLab.hidden = YES; } [self.buninessLabel mas_makeConstraints:^(MASConstraintMaker *make) { make.left.equalTo(_authorLab.mas_right).offset(ISEmptyNumber(model.Author) ? 0 : 24); make.top.equalTo(self.authorLab); make.width.mas_lessThanOrEqualTo(60); }]; if (!ISEmptyNumber(model.Source)) { _buninessLabel.text = model.Source; UIView *lineViewB = [UIView new]; lineViewB.backgroundColor = kColorFromRGB(0xe5e5e5); [self addSubview:lineViewB]; [lineViewB mas_makeConstraints:^(MASConstraintMaker *make) { make.left.equalTo(_buninessLabel.mas_right).offset(12); make.top.equalTo(_authorLab).offset(2); make.height.mas_equalTo(12.5); make.width.mas_equalTo(1); }]; self.lineViewB = lineViewB; } else { _buninessLabel.hidden = YES; } _timeLabel.text = ISEmptyString(model.AddDate)?@"暂无":[ZYCTool yearMonthAndDay:model.AddDate]; [self.timeLabel mas_makeConstraints:^(MASConstraintMaker *make) { make.left.equalTo(_buninessLabel.mas_right).offset(ISEmptyNumber(model.Source) ? 0 : 24); make.top.equalTo(self.authorLab); make.width.mas_lessThanOrEqualTo(84); }]; if (!ISEmptyNumber(model.AddDate)) { UIView *lineViewC = [UIView new]; lineViewC.backgroundColor = kColorFromRGB(0xe5e5e5); [self addSubview:lineViewC]; [lineViewC mas_makeConstraints:^(MASConstraintMaker *make) { make.left.equalTo(self.timeLabel.mas_right).offset(12); make.top.equalTo(_authorLab).offset(2); make.height.mas_equalTo(12.5); make.width.mas_equalTo(1); }]; self.lineViewC = lineViewC; }else{ self.timeLabel.hidden = YES; } [self layoutIfNeeded]; NSString *tmpStr = [NSString stringWithFormat:@"阅读:%@",@(model.ReadCount)]; // 计算剩余宽度 CGFloat maxWidth = kScreenWidth - CGRectGetMaxX(self.timeLabel.frame) - 10; // 22 右边距 // 计算文字宽度 CGFloat textWidth = [NSString sizeWith:CGSizeMake(MAXFLOAT, self.timeLabel.height) font:[UIFont systemFontOfSize:14.f] text:tmpStr].width; if (textWidth <= maxWidth) { // 放的下就一排显示 self.readLab.text = tmpStr; } else { // 放不下就两排显示 self.readLab.text = [NSString stringWithFormat:@"阅读:\n%@",@(model.ReadCount)]; } [self.readLab mas_makeConstraints:^(MASConstraintMaker *make) { make.left.equalTo(self.timeLabel.mas_right).offset(ISEmptyNumber(model.AddDate) ? 0 : 24); make.top.equalTo(self.authorLab); make.width.mas_lessThanOrEqualTo(58); }]; if (_authorLab.height > _buninessLabel.height) { topMargin += _authorLab.height; }else{ topMargin += _buninessLabel.height; } topMargin += 14.0f; CGRect frame = self.frame; frame.size.height = topMargin; self.frame = frame; } - (void)loadTitleModel2:(Item *)model{ // [self loadTitleModel:model]; CGFloat topMargin = 14.f; CGFloat leftMargin = 22.f; CGFloat titleW = 10.f; _titleLabel.textColor = [UIColor hexStringToColor:@"0A0A0A"]; _titleLabel.font = [UIFont systemFontOfSize:23.f]; if (!ISEmptyString(model.Title)) { _titleLabel.text = model.Title; [ZYCTool setLabelSpace:_titleLabel withSpace:titleW withFont:_titleLabel.font]; CGSize titleSize = [_titleLabel sizeThatFits:CGSizeMake(kGXScreenWidth-20*2, MAXFLOAT)]; _titleLabel.frame = CGRectMake(leftMargin, topMargin, titleSize.width, titleSize.height); topMargin += titleSize.height; } else { _titleLabel.hidden = YES; } topMargin += 21.f; CGFloat MarginW = leftMargin; if (!ISEmptyNumber(model.Author)) { _authorLab.text = model.Author; CGSize authorSize = [_authorLab sizeThatFits:CGSizeZero]; _authorLab.frame = CGRectMake(leftMargin, topMargin, authorSize.width, authorSize.height); } else { _authorLab.hidden = YES; self.lineViewA.hidden = YES; } if (!ISEmptyString(model.Source)) { _buninessLabel.text = model.Source; CGSize buninessSize = [_buninessLabel sizeThatFits:CGSizeZero]; MarginW += _authorLab.width + 24; _buninessLabel.frame = CGRectMake(MarginW, topMargin, buninessSize.width, buninessSize.height); }else{ _buninessLabel.hidden = YES; self.lineViewB.hidden = YES; } if (!ISEmptyString(model.AddDate)) { _timeLabel.text = [ZYCTool yearMonthAndDay:model.AddDate]; CGSize timeSize = [_timeLabel sizeThatFits:CGSizeZero]; MarginW += _buninessLabel.width + 24; _timeLabel.frame = CGRectMake(MarginW, topMargin, timeSize.width, timeSize.height); }else{ _timeLabel.hidden = YES; self.lineViewC.hidden = YES; } _readLab.text = @"阅读:"; CGSize readSize = [_readLab sizeThatFits:CGSizeZero]; _readLab.frame = CGRectMake(MarginW + 12, topMargin ,readSize.width,readSize.height); _readNumLab.text = [NSString stringWithFormat:@"%ld",(long)model.ReadCount]; CGSize checkSize = [_readNumLab sizeThatFits:CGSizeZero]; _readNumLab.frame = CGRectMake(CGRectGetMaxX(_readLab.frame), topMargin, checkSize.width, checkSize.height); // _timeLabel.text = ISEmptyString(model.lastEditDate)?@"暂无":model.lastEditDate; // CGSize timeSize = [_timeLabel sizeThatFits:CGSizeZero]; // _timeLabel.frame = CGRectMake(20, topMargin, timeSize.width, timeSize.height); // _checkImgVi.frame = CGRectMake(20 + timeSize.width + 20, topMargin + (timeSize.height - 9)/2.0 , 13, 9); // _readNumLab.text = [NSString stringWithFormat:@"%@", ISEmptyNumber(model.hits)?@0:model.hits]; // CGSize checkSize = [_readNumLab sizeThatFits:CGSizeZero]; // _readNumLab.frame = CGRectMake(20 + timeSize.width + 20 + 13 + 2, topMargin, checkSize.width, checkSize.height); // topMargin += _authorLab.height; topMargin += 8.f; self.checkImgVi.hidden = YES; self.readLab.hidden = YES; CGSize shoujianSize = [_shoujianrenlab sizeThatFits:CGSizeMake(kGXScreenWidth-20*2, MAXFLOAT)]; _shoujianrenlab.frame = CGRectMake(22.f, topMargin, shoujianSize.width, shoujianSize.height); topMargin += shoujianSize.height; topMargin += 8.f; CGSize haveReadSize = [_haveReadNumberlab sizeThatFits:CGSizeMake(kGXScreenWidth-20*2, MAXFLOAT)]; _haveReadNumberlab.frame = CGRectMake(22.f, topMargin, haveReadSize.width, haveReadSize.height); CGSize haveReadBtnSize = [_noticButton sizeThatFits:CGSizeMake(kGXScreenWidth-20*2, MAXFLOAT)]; _noticButton.frame = CGRectMake(CGRectGetMaxX(self.haveReadNumberlab.frame), topMargin, haveReadBtnSize.width,17); CGSize noReadSize = [_noReadNumberlab sizeThatFits:CGSizeMake(kGXScreenWidth-20*2, MAXFLOAT)]; _noReadNumberlab.frame = CGRectMake(22.f+haveReadSize.width+haveReadBtnSize.width, topMargin, noReadSize.width, noReadSize.height); topMargin += haveReadSize.height; topMargin += 14.f; CGRect frame = self.frame; frame.size.height = topMargin; self.frame = frame; } #pragma mark - setter - (UILabel *)titleLabel { if (!_titleLabel) { _titleLabel = [UILabel new]; _titleLabel.numberOfLines = 0; _titleLabel.font = [UIFont systemFontOfSize:23.f]; _titleLabel.textColor = UIColorHex(0A0A0A); } return _titleLabel; } - (UILabel *)timeLabel { if (!_timeLabel) { _timeLabel = [UILabel new]; _timeLabel.font = [UIFont systemFontOfSize:14.f]; _timeLabel.textColor = UIColorHex(999999); _timeLabel.textAlignment = NSTextAlignmentCenter; _timeLabel.numberOfLines = 0; } return _timeLabel; } - (UILabel *)buninessLabel { if (!_buninessLabel) { _buninessLabel = [UILabel new]; _buninessLabel.font = [UIFont systemFontOfSize:14.f]; _buninessLabel.textColor = UIColorHex(999999); _buninessLabel.numberOfLines = 0; _buninessLabel.textAlignment = NSTextAlignmentCenter; } return _buninessLabel; } - (UIImageView *)checkImgVi { if (!_checkImgVi) { _checkImgVi = [[UIImageView alloc] init]; [_checkImgVi setImage:IMG(@"icon_browse")]; } return _checkImgVi; } - (UILabel *)readLab{ if (!_readLab){ _readLab = [UILabel new]; _readLab.font = [UIFont systemFontOfSize:14.f]; _readLab.textColor = UIColorHex(999999); _readLab.numberOfLines = 0; _readLab.textAlignment = NSTextAlignmentCenter; } return _readLab; } - (UILabel *)readNumLab { if (!_readNumLab) { _readNumLab = [UILabel new]; _readNumLab.font = [UIFont systemFontOfSize:14.f]; _readNumLab.textColor = UIColorHex(999999); } return _readNumLab; } - (UILabel *)authorLab { if (!_authorLab) { _authorLab = [UILabel new]; _authorLab.font = [UIFont systemFontOfSize:14.f]; _authorLab.textColor = UIColorHex(999999); _authorLab.numberOfLines = 0; _authorLab.textAlignment = NSTextAlignmentCenter; } return _authorLab; } - (UILabel *)refereeLab { if (!_refereeLab) { _refereeLab = [UILabel new]; _refereeLab.font = [UIFont systemFontOfSize:14.f]; _refereeLab.textColor = UIColorHex(999999); } return _refereeLab; } - (UILabel *)shoujianrenlab{ if (!_shoujianrenlab) { _shoujianrenlab = [UILabel new]; _shoujianrenlab.font = [UIFont systemFontOfSize:14.f]; _shoujianrenlab.textColor = UIColorHex(999999); _shoujianrenlab.text = @"收件人:编辑部、重要人员、广西出版传媒部"; } return _shoujianrenlab; } - (UILabel *)haveReadNumberlab{ if (!_haveReadNumberlab) { _haveReadNumberlab = [UILabel new]; _haveReadNumberlab.font = [UIFont systemFontOfSize:14.f]; _haveReadNumberlab.textColor = UIColorHex(999999); _haveReadNumberlab.text = @"已读:"; } return _haveReadNumberlab; } - (TDButton *)noticButton{ if (!_noticButton) { _noticButton = [[TDButton alloc]init]; [_noticButton setTitle:@"542" forState:UIControlStateNormal]; [_noticButton setTitleColor:UIColorHex(1F87DB) forState:UIControlStateNormal]; [_noticButton addTarget:self action:@selector(didReadNumHander:) forControlEvents:UIControlEventTouchDown]; [[_noticButton titleLabel] setFont:[UIFont systemFontOfSize:14.f]]; [[_noticButton titleLabel] setTextAlignment:NSTextAlignmentRight]; } return _noticButton; } - (UILabel *)noReadNumberlab{ if (!_noReadNumberlab) { _noReadNumberlab = [UILabel new]; _noReadNumberlab.text = @"/687"; _noReadNumberlab.textColor = k9; _noReadNumberlab.font = [UIFont systemFontOfSize:14.f]; } return _noReadNumberlab; } - (void)didReadNumHander:(TDButton *)sender{ if ([self.delegate respondsToSelector:@selector(didDetailTitlefunctionTouch:)]) { [self.delegate didDetailTitlefunctionTouch:sender]; } } @end