You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
338 lines
14 KiB
338 lines
14 KiB
// |
|
// TFNovelDetailHeaderView.m |
|
// TFReader |
|
// |
|
// Created by 谢腾飞 on 2020/12/19. |
|
// Copyright © 2020 xtfei_2011@126.com. All rights reserved. |
|
// |
|
|
|
#import "TFNovelDetailHeaderView.h" |
|
#import "TFTagboardView.h" |
|
#import "UIImage+Blur.h" |
|
|
|
@interface TFNovelDetailHeaderView () |
|
{ |
|
TFProductionCoverView *bookImageView; |
|
UILabel *bookNameLabel; |
|
UILabel *authorLabel; |
|
UILabel *introductionLabel; |
|
UILabel *commontNumLabel; |
|
UILabel *collecitonNumLabel; |
|
|
|
UILabel *bookDescriptionLabel; |
|
UILabel *timeLabel; |
|
UIButton *catalogueButton; |
|
UILabel *catalogueDetailLabel; |
|
TFTagboardView *tagView; |
|
|
|
} |
|
@property (nonatomic, strong) UIImageView __block *headBackImageView; |
|
|
|
@end |
|
|
|
@implementation TFNovelDetailHeaderView |
|
|
|
- (void)createSubviews |
|
{ |
|
[super createSubviews]; |
|
|
|
// 背景图 |
|
_headBackImageView = [[UIImageView alloc] init]; |
|
_headBackImageView.backgroundColor = [UIColor whiteColor]; |
|
_headBackImageView.contentMode = UIViewContentModeScaleAspectFill; |
|
_headBackImageView.clipsToBounds = YES; |
|
_headBackImageView.image = HoldImage; |
|
[self.contentView addSubview:_headBackImageView]; |
|
|
|
[_headBackImageView mas_makeConstraints:^(MASConstraintMaker *make) { |
|
make.left.mas_equalTo(self.contentView.mas_left); |
|
make.top.mas_equalTo(self.contentView.mas_top); |
|
make.width.mas_equalTo(SCREEN_WIDTH); |
|
make.height.mas_equalTo(SCREEN_WIDTH / 2 + PUB_NAVBAR_OFFSET + kMargin); |
|
}]; |
|
|
|
// 书籍图片 |
|
bookImageView = [[TFProductionCoverView alloc] initWithProductionType:TFProductionTypeNovel coverDirection:TFProductionCoverDirectionVertical]; |
|
bookImageView.userInteractionEnabled = YES; |
|
[self.contentView addSubview:bookImageView]; |
|
|
|
[bookImageView mas_makeConstraints:^(MASConstraintMaker *make) { |
|
make.left.mas_equalTo(kMargin); |
|
make.bottom.mas_equalTo(_headBackImageView.mas_bottom).with.offset(kMargin); |
|
make.width.mas_equalTo(BOOK_WIDTH); |
|
make.height.mas_equalTo(BOOK_HEIGHT); |
|
}]; |
|
|
|
// 书名 |
|
bookNameLabel = [[UILabel alloc] init]; |
|
bookNameLabel.textAlignment = NSTextAlignmentLeft; |
|
bookNameLabel.textColor = [UIColor whiteColor]; |
|
bookNameLabel.backgroundColor = [UIColor clearColor]; |
|
bookNameLabel.font = kBoldFont16; |
|
[self.contentView addSubview:bookNameLabel]; |
|
|
|
[bookNameLabel mas_makeConstraints:^(MASConstraintMaker *make) { |
|
make.left.mas_equalTo(bookImageView.mas_right).with.offset(kMargin); |
|
make.top.mas_equalTo(bookImageView.mas_top); |
|
make.right.mas_equalTo(self.contentView.mas_right).with.offset(- kMargin); |
|
make.height.mas_equalTo(kLabelHeight); |
|
}]; |
|
|
|
// 作者 |
|
authorLabel = [[UILabel alloc] init]; |
|
authorLabel.backgroundColor = [UIColor clearColor]; |
|
authorLabel.textColor = [UIColor whiteColor]; |
|
authorLabel.textAlignment = NSTextAlignmentLeft; |
|
authorLabel.font = kFont12; |
|
[self.contentView addSubview:authorLabel]; |
|
|
|
[authorLabel mas_makeConstraints:^(MASConstraintMaker *make) { |
|
make.left.mas_equalTo(bookNameLabel.mas_left); |
|
make.top.mas_equalTo(bookNameLabel.mas_bottom).with.offset(5); |
|
make.width.mas_equalTo(bookNameLabel.mas_width).multipliedBy(0.5); |
|
make.height.mas_equalTo(17); |
|
}]; |
|
|
|
// 书籍标签 |
|
introductionLabel = [[UILabel alloc] init]; |
|
introductionLabel.backgroundColor = [UIColor clearColor]; |
|
introductionLabel.textColor = [UIColor whiteColor]; |
|
introductionLabel.textAlignment = NSTextAlignmentLeft; |
|
introductionLabel.font = kFont12; |
|
[self.contentView addSubview:introductionLabel]; |
|
|
|
[introductionLabel mas_makeConstraints:^(MASConstraintMaker *make) { |
|
make.left.mas_equalTo(bookNameLabel.mas_left); |
|
make.top.mas_equalTo(authorLabel.mas_bottom).with.offset(5); |
|
make.width.mas_equalTo(bookNameLabel.mas_width).multipliedBy(0.5); |
|
make.height.mas_equalTo(authorLabel.mas_height); |
|
}]; |
|
|
|
// 评价数 |
|
commontNumLabel = [[UILabel alloc] init]; |
|
commontNumLabel.backgroundColor = [UIColor clearColor]; |
|
commontNumLabel.textColor = [UIColor whiteColor]; |
|
commontNumLabel.textAlignment = NSTextAlignmentLeft; |
|
commontNumLabel.font = kFont12; |
|
[self.contentView addSubview:commontNumLabel]; |
|
|
|
[commontNumLabel mas_makeConstraints:^(MASConstraintMaker *make) { |
|
make.left.mas_equalTo(bookNameLabel.mas_left); |
|
make.top.mas_equalTo(introductionLabel.mas_bottom).with.offset(kQuarterMargin); |
|
make.width.mas_equalTo(bookNameLabel.mas_width).multipliedBy(0.5); |
|
make.height.mas_equalTo(authorLabel.mas_height); |
|
}]; |
|
|
|
collecitonNumLabel = [[UILabel alloc] init]; |
|
collecitonNumLabel.backgroundColor = [UIColor clearColor]; |
|
collecitonNumLabel.textColor = [UIColor whiteColor]; |
|
collecitonNumLabel.textAlignment = NSTextAlignmentLeft; |
|
collecitonNumLabel.font = kFont12; |
|
[self.contentView addSubview:collecitonNumLabel]; |
|
|
|
[collecitonNumLabel mas_makeConstraints:^(MASConstraintMaker *make) { |
|
make.left.mas_equalTo(bookNameLabel.mas_left); |
|
make.top.mas_equalTo(commontNumLabel.mas_bottom).with.offset(kQuarterMargin); |
|
make.width.mas_equalTo(bookNameLabel.mas_width).multipliedBy(0.5); |
|
make.height.mas_equalTo(authorLabel.mas_height); |
|
}]; |
|
|
|
// 简介 |
|
bookDescriptionLabel = [[UILabel alloc] init]; |
|
bookDescriptionLabel.backgroundColor = [UIColor whiteColor]; |
|
bookDescriptionLabel.textColor = kBlackColor; |
|
bookDescriptionLabel.textAlignment = NSTextAlignmentLeft; |
|
bookDescriptionLabel.font = kMainFont; |
|
bookDescriptionLabel.numberOfLines = 0; |
|
[self.contentView addSubview:bookDescriptionLabel]; |
|
|
|
[bookDescriptionLabel mas_makeConstraints:^(MASConstraintMaker *make) { |
|
make.left.mas_equalTo(kMargin); |
|
make.top.mas_equalTo(bookImageView.mas_bottom).with.offset(kHalfMargin); |
|
make.width.mas_equalTo(self.mas_width).with.offset(- 2 * kMargin); |
|
make.height.mas_equalTo(50); |
|
}]; |
|
|
|
// 目录列 |
|
catalogueButton = [UIButton buttonWithType:UIButtonTypeCustom]; |
|
catalogueButton.backgroundColor = [UIColor clearColor]; |
|
catalogueButton.hidden = YES; |
|
[catalogueButton addTarget:self action:@selector(catalogueClick) forControlEvents:UIControlEventTouchUpInside]; |
|
[self.contentView addSubview:catalogueButton]; |
|
|
|
[catalogueButton mas_makeConstraints:^(MASConstraintMaker *make) { |
|
make.left.mas_equalTo(0); |
|
make.top.mas_equalTo(bookDescriptionLabel.mas_bottom).with.offset(kHalfMargin); |
|
make.width.mas_equalTo(self.contentView.mas_width); |
|
make.height.mas_equalTo(kLabelHeight + kHalfMargin); |
|
}]; |
|
|
|
UIImageView *catalogueIcon = [[UIImageView alloc] init]; |
|
catalogueIcon.image = [UIImage imageNamed:@"book_directory"]; |
|
catalogueIcon.userInteractionEnabled = YES; |
|
[catalogueButton addSubview:catalogueIcon]; |
|
|
|
[catalogueIcon mas_makeConstraints:^(MASConstraintMaker *make) { |
|
make.left.mas_equalTo(kMargin); |
|
make.centerY.mas_equalTo(catalogueButton.mas_centerY); |
|
make.height.mas_equalTo(kMargin); |
|
make.width.mas_equalTo(kMargin); |
|
}]; |
|
|
|
UILabel *catalogueTitle = [[UILabel alloc] init]; |
|
catalogueTitle.text = TFLocalizedString(@"目录"); |
|
catalogueTitle.font = kMainFont; |
|
catalogueTitle.textColor = kBlackColor; |
|
catalogueTitle.textAlignment = NSTextAlignmentLeft; |
|
[catalogueButton addSubview:catalogueTitle]; |
|
|
|
[catalogueTitle mas_makeConstraints:^(MASConstraintMaker *make) { |
|
make.left.mas_equalTo(catalogueIcon.mas_right).with.offset(5); |
|
make.centerY.mas_equalTo(catalogueIcon.mas_centerY); |
|
make.width.mas_equalTo(catalogueTitle.intrinsicContentSize.width); |
|
make.height.mas_equalTo(catalogueIcon.mas_height); |
|
}]; |
|
|
|
// 横线 |
|
for (int i = 0; i < 2; i ++) { |
|
UIView *cellLine = [[UIView alloc] init]; |
|
cellLine.hidden = NO; |
|
cellLine.backgroundColor = kGrayLineColor; |
|
[catalogueButton addSubview:cellLine]; |
|
|
|
[cellLine mas_makeConstraints:^(MASConstraintMaker *make) { |
|
make.left.mas_equalTo(kMargin); |
|
if (i == 0) { |
|
make.top.mas_equalTo(kCellLineHeight); |
|
} else { |
|
make.bottom.mas_equalTo(catalogueButton.mas_bottom).with.offset(- kCellLineHeight); |
|
} |
|
make.width.mas_equalTo(self.mas_width).with.offset( - kMargin); |
|
make.height.mas_equalTo(kCellLineHeight); |
|
}]; |
|
} |
|
|
|
UIImageView *connerImageView = [[UIImageView alloc] init]; |
|
connerImageView.image = [[UIImage imageNamed:@"public_more"] imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate]; |
|
connerImageView.userInteractionEnabled = YES; |
|
connerImageView.tintColor = kGrayTextColor; |
|
[catalogueButton addSubview:connerImageView]; |
|
|
|
[connerImageView mas_makeConstraints:^(MASConstraintMaker *make) { |
|
make.right.mas_equalTo(catalogueButton.mas_right).with.offset(- kMargin); |
|
make.centerY.mas_equalTo(catalogueButton.mas_centerY); |
|
make.width.height.mas_equalTo(10); |
|
}]; |
|
|
|
timeLabel = [[UILabel alloc] init]; |
|
timeLabel.textAlignment = NSTextAlignmentRight; |
|
timeLabel.font = kFont10; |
|
timeLabel.textColor = kGrayTextColor; |
|
[catalogueButton addSubview:timeLabel]; |
|
|
|
[timeLabel mas_makeConstraints:^(MASConstraintMaker *make) { |
|
make.right.mas_equalTo(connerImageView.mas_left).with.offset(- kQuarterMargin); |
|
make.top.mas_equalTo(0); |
|
make.width.mas_equalTo(CGFLOAT_MIN); |
|
make.height.mas_equalTo(catalogueButton.mas_height); |
|
}]; |
|
|
|
catalogueDetailLabel = [[UILabel alloc] init]; |
|
catalogueDetailLabel.backgroundColor = [UIColor clearColor]; |
|
catalogueDetailLabel.textAlignment = NSTextAlignmentLeft; |
|
catalogueDetailLabel.font = kFont12; |
|
catalogueDetailLabel.textColor = kGrayTextColor; |
|
[catalogueButton addSubview:catalogueDetailLabel]; |
|
|
|
[catalogueDetailLabel mas_makeConstraints:^(MASConstraintMaker *make) { |
|
make.left.mas_equalTo(catalogueTitle.mas_right).offset(kQuarterMargin); |
|
make.top.mas_equalTo(0); |
|
make.right.mas_equalTo(timeLabel.mas_left).with.offset(- kQuarterMargin); |
|
make.height.mas_equalTo(catalogueButton.mas_height); |
|
}]; |
|
|
|
// 标签 |
|
tagView = [[TFTagboardView alloc] init]; |
|
tagView.textAlignment = TFTagboardTextAlignmentLeft; |
|
tagView.borderStyle = TFTagboardBorderStyleFill; |
|
tagView.layoutStyle = TFTagboardLayoutStyleScroll; |
|
[self.contentView addSubview:tagView]; |
|
|
|
[tagView mas_makeConstraints:^(MASConstraintMaker *make) { |
|
make.left.mas_equalTo(kMargin); |
|
make.top.mas_equalTo(catalogueButton.mas_bottom).with.offset(kHalfMargin); |
|
make.width.mas_equalTo(self.contentView.mas_width).with.offset(- 2 * kMargin); |
|
make.height.mas_equalTo(20); |
|
make.bottom.mas_equalTo(self.contentView.mas_bottom).with.offset(- kHalfMargin).priorityLow(); |
|
}]; |
|
|
|
} |
|
|
|
- (void)catalogueClick |
|
{ |
|
if (self.catalogueButtonClickBlock) { |
|
self.catalogueButtonClickBlock(); |
|
} |
|
} |
|
|
|
- (void)setBookModel:(TFProductionModel *)bookModel |
|
{ |
|
if (bookModel && (_bookModel != bookModel)) { |
|
_bookModel = bookModel; |
|
|
|
WS(weakSelf) |
|
[[YYWebImageManager sharedManager] requestImageWithURL:[NSURL URLWithString:bookModel.cover?:@""] options:YYWebImageOptionSetImageWithFadeAnimation progress:nil transform:nil completion:^(UIImage * _Nullable image, NSURL * _Nonnull url, YYWebImageFromType from, YYWebImageStage stage, NSError * _Nullable error) { |
|
dispatch_async(dispatch_get_main_queue(), ^{ |
|
weakSelf.headBackImageView.image = [image imgWithLightAlpha:0.4 radius:3 colorSaturationFactor:1.8]; |
|
}); |
|
}]; |
|
|
|
bookImageView.coverImageUrl = bookModel.cover; |
|
|
|
bookNameLabel.text = [TFUtilsHelper formatStringWithObject:bookModel.name?:@""]; |
|
|
|
authorLabel.text = [TFUtilsHelper formatStringWithObject:bookModel.author?:@""]; |
|
|
|
[introductionLabel mas_remakeConstraints:^(MASConstraintMaker *make) { |
|
make.left.mas_equalTo(bookNameLabel.mas_left); |
|
make.top.mas_equalTo(authorLabel.mas_bottom).with.offset(5); |
|
make.width.mas_equalTo(bookNameLabel.mas_width); |
|
make.height.mas_equalTo(authorLabel.mas_height); |
|
}]; |
|
|
|
commontNumLabel.text = [TFUtilsHelper formatStringWithObject:bookModel.hot_num?:@""]; |
|
|
|
collecitonNumLabel.text = [TFUtilsHelper formatStringWithObject:bookModel.total_favors?:@""]; |
|
|
|
// 截取简介 |
|
NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] initWithString:bookModel.production_descirption?:@""]; |
|
attributedString.lineSpacing = 5; |
|
attributedString.font = kFont(13); |
|
attributedString.color = kBlackColor; |
|
|
|
NSAttributedString *separatedString = [TFViewHelper getSubContentWithOriginalContent:attributedString labelWidth:(SCREEN_WIDTH - 2 * (kMargin + kHalfMargin)) labelMaxLine:4]; |
|
bookDescriptionLabel.attributedText = separatedString; |
|
if (separatedString.length == 0) { |
|
[bookDescriptionLabel mas_updateConstraints:^(MASConstraintMaker *make) { |
|
make.height.mas_equalTo(0.0); |
|
}]; |
|
} else { |
|
[bookDescriptionLabel mas_updateConstraints:^(MASConstraintMaker *make) { |
|
make.height.mas_equalTo([TFViewHelper boundsWithFont:kFont(13) attributedText:separatedString needWidth:(SCREEN_WIDTH - 2 * (kMargin + kHalfMargin)) lineSpacing:6] + kHalfMargin); |
|
}]; |
|
} |
|
|
|
tagView.tagboardArray = bookModel.tag; |
|
|
|
timeLabel.text = bookModel.last_chapter_time?:@""; |
|
[timeLabel mas_updateConstraints:^(MASConstraintMaker *make) { |
|
make.width.mas_equalTo([TFViewHelper getDynamicWidthWithLabel:timeLabel]); |
|
}]; |
|
|
|
catalogueDetailLabel.text = bookModel.last_chapter?:@""; |
|
|
|
catalogueButton.hidden = NO; |
|
} |
|
} |
|
|
|
@end
|
|
|