12207480 / TYAttributedLabel

TYAttributedLabel 简单,强大的属性文本控件(无需了解CoreText),支持图文混排显示,支持添加链接,image和UIView控件,支持自定义排版显示
MIT License
2.89k stars 570 forks source link

cell中,在每次更改文本内容后设置paragraphSpacing,无效 #118

Closed iOSleep closed 6 years ago

iOSleep commented 6 years ago

image

界面使用 autolayout 布局

// cell
- (void)configModel:(ExamQuestionDetail *)model {
  self.infoLabel.attributedText = nil;

  for (NSInteger i = 0; i < model.question.models.count; i++) {
    ExamQuestionModel *one = model.question.models[i];
    if (one.type == ExamQuestionModelTypeText) {
      ExamQuestionTextModel *tmp = (ExamQuestionTextModel *)one;
      [self.infoLabel appendTextAttributedString:tmp.defaultString];
    }
  }
  self.infoLabel.paragraphSpacing = ExamQuestionTextParaDefaultHeight;
}

// view controller
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
//  ExamPaperModel *paper = self.lv2Array[indexPath.section];
  ExamPaperModel *paper = self.lv2Array[2];
  ExamQuestionDetail *model = paper.content.question_detail[indexPath.row];
  ExamReportTextCell *cell = [tableView dequeueReusableCellWithIdentifier:kTextCell forIndexPath:indexPath];
// 没有其他对 cell 的操作了
  [cell configModel:model];

  return cell;
}
iOSleep commented 6 years ago

已解决,查看源码发现如果 spcing 相同不会重新结算,在配置的时候先重置此选项。

self.infoLabel.paragraphSpacing = 0;