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.
95 lines
3.9 KiB
95 lines
3.9 KiB
// |
|
// TFComicDetailIntroductionCell.m |
|
// TFReader |
|
// |
|
// Created by 谢腾飞 on 2020/12/19. |
|
// Copyright © 2020 xtfei_2011@126.com. All rights reserved. |
|
// |
|
|
|
#import "TFComicDetailIntroductionCell.h" |
|
|
|
@interface TFComicDetailIntroductionCell () |
|
{ |
|
UILabel *introductionLabel; |
|
UILabel *introductionContent; |
|
} |
|
@end |
|
|
|
@implementation TFComicDetailIntroductionCell |
|
|
|
- (void)createSubviews |
|
{ |
|
[super createSubviews]; |
|
|
|
introductionLabel = [[UILabel alloc] init]; |
|
introductionLabel.text = TFLocalizedString(@"作品简介"); |
|
introductionLabel.textColor = kGrayTextDeepColor; |
|
introductionLabel.textAlignment = NSTextAlignmentLeft; |
|
introductionLabel.font = kMainFont; |
|
[self.contentView addSubview:introductionLabel]; |
|
[introductionLabel mas_makeConstraints:^(MASConstraintMaker *make) { |
|
make.left.mas_equalTo(self.contentView.mas_left).with.offset(kMargin); |
|
make.top.mas_equalTo(self.contentView.mas_top).with.offset(kMargin); |
|
make.right.mas_equalTo(self.contentView.mas_right).with.offset(- kMargin); |
|
make.height.mas_equalTo(0.0); |
|
}]; |
|
|
|
introductionContent = [[UILabel alloc] init]; |
|
introductionContent.textColor = kGrayTextColor; |
|
introductionContent.textAlignment = NSTextAlignmentLeft; |
|
introductionContent.font = kFont12; |
|
introductionContent.numberOfLines = 0; |
|
[self.contentView addSubview:introductionContent]; |
|
[introductionContent mas_makeConstraints:^(MASConstraintMaker *make) { |
|
make.left.mas_equalTo(introductionLabel.mas_left); |
|
make.top.mas_equalTo(self.contentView.mas_top).offset(kHalfMargin); |
|
make.right.mas_equalTo(introductionLabel.mas_right); |
|
}]; |
|
|
|
UIView *splitLine = [[UIView alloc] init]; |
|
splitLine.backgroundColor = [UIColor clearColor]; |
|
[self.contentView addSubview:splitLine]; |
|
[splitLine mas_makeConstraints:^(MASConstraintMaker *make) { |
|
make.height.mas_equalTo(0.1); |
|
make.right.bottom.left.equalTo(self.contentView); |
|
make.top.equalTo(introductionContent.mas_bottom).offset(kHalfMargin).priorityLow(); |
|
}]; |
|
} |
|
|
|
- (void)setComicModel:(TFProductionModel *)comicModel |
|
{ |
|
if (_comicModel != comicModel) { |
|
_comicModel = comicModel; |
|
|
|
if (comicModel.production_descirption.length > 0) { |
|
|
|
NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] initWithString:comicModel.production_descirption?:@""]; |
|
attributedString.lineSpacing = 6; |
|
attributedString.font = kFont12; |
|
attributedString.color = kGrayTextColor; |
|
|
|
YYTextLayout *layout = [YYTextLayout layoutWithContainerSize:CGSizeMake(SCREEN_WIDTH - 2 * kMargin, MAXFLOAT) text:attributedString]; |
|
|
|
if (layout.rowCount < 5) { |
|
introductionContent.attributedText = attributedString; |
|
} else { |
|
// 截取前5行的内容 |
|
YYTextLine *lastLine = layout.lines[4]; |
|
NSMutableAttributedString *t_atr = [[attributedString attributedSubstringFromRange:NSMakeRange(0, lastLine.range.location + lastLine.range.length)] mutableCopy]; |
|
// 截取第5行一半的内容 |
|
CGFloat maxWidth = (SCREEN_WIDTH - 2 * kMargin) / 2.0; |
|
if (lastLine.lineWidth > maxWidth) { |
|
// 获取多出来的距离 |
|
CGFloat spacing = lastLine.lineWidth - maxWidth; |
|
// 获取多余的文字个数(多余的间距 / 单个字的宽度) |
|
NSInteger number = spacing / (lastLine.lineWidth / lastLine.range.length); |
|
t_atr = [[t_atr attributedSubstringFromRange:NSMakeRange(0, t_atr.length - number - 1)] mutableCopy]; |
|
[t_atr appendString:@" ..."]; |
|
} |
|
introductionContent.attributedText = t_atr; |
|
} |
|
} |
|
} |
|
} |
|
|
|
@end
|
|
|