12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970 |
- //
- // RQExercisExplainItemViewModel.m
- // JSJP
- //
- // Created by 张嵘 on 2022/7/3.
- //
- #import "RQExercisExplainItemViewModel.h"
- @interface RQExercisExplainItemViewModel ()
- @property (nonatomic, readwrite, strong) RQExerciseModel *exerciseModel;
- @property (nonatomic, readwrite, strong) YYLabel *yyLabel;
- @property (nonatomic, readwrite, strong) NSMutableAttributedString *explainString;
- @end
- @implementation RQExercisExplainItemViewModel
- - (instancetype)initWithRQExerciseModel:(RQExerciseModel *)exerciseModel {
- if (self = [super init]) {
- @weakify(self)
- dispatch_async(dispatch_get_main_queue(), ^{
- @strongify(self)
-
- self.exerciseModel = exerciseModel;
- CGFloat headerHeight = 16.f + 26.f + 16.f;
- CGFloat textHeight = 0;
- CGFloat footerHeight = 16.f + 18.f + 16.f;
- if (!RQObjectIsNil(exerciseModel.ydtQuestionModel)) {
- if (RQStringIsNotEmpty(exerciseModel.ydtQuestionModel.explain)) {
- NSMutableAttributedString *text = [[NSMutableAttributedString alloc] initWithString:exerciseModel.ydtQuestionModel.explain];
- text.yy_font = [UIFont systemFontOfSize:RQ_Exercise_Module.exerciseFontSize];
- text.yy_lineSpacing = 8;
- text.yy_color = RQ_MAIN_TEXT_COLOR_1;
- self.explainString = text;
- CGFloat height = [self getMessageHeightWithAttributedStr:text andLabel:self.yyLabel];
- textHeight = height;
- }
- }
-
- self.rowHeight = headerHeight + textHeight + footerHeight;
- });
-
-
-
- }
- return self;
- }
- - (CGFloat)getMessageHeightWithAttributedStr:(NSMutableAttributedString *)attributedStr andLabel:(YYLabel *)lb {
- lb.attributedText = attributedStr;
- CGSize introSize = CGSizeMake(RQ_SCREEN_WIDTH - (16 * 2) - (8 * 2), CGFLOAT_MAX);
- YYTextLayout *layout = [YYTextLayout layoutWithContainerSize:introSize text:attributedStr];
- lb.textLayout = layout;
- CGFloat introHeight = layout.textBoundingSize.height;
- return introHeight;
- }
- - (YYLabel *)yyLabel {
- if (!_yyLabel) {
- _yyLabel = [[YYLabel alloc] init];
- }
- return _yyLabel;
- }
- - (NSString *)itemClassName {
- return @"RQExercisExplainCell";
- }
- @end
|