似乎只有在单词换行到下一行时才会发生,但如果我做了一个没有自动换行的列表,它会正确显示高度(例如:
@"1<br/><br/>
2<br/><br/>
...
200"
这将显示每一行,但这将切断该行:
@"SUPER LONG LINE WITH A LOT OF TEXT and WRAPS TO THE NEXT LINE<br/><br/>
...
LAST LINE WONT BE VISIBLE BECAUSE THE HEIGHT IS OFF"
////// 这是我加载单元格高度的位置(如果我在这里调整高度,我可以查看其余内容): //////带桌子的课程//////
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell = [self populateCell:tableView indexPath:indexPath];
[cell setNeedsDisplay];
[cell layoutIfNeeded];
[cell.contentView systemLayoutSizeFittingSize:UILayoutFittingCompressedSize].height
//////自定义单元格类////
for (NSString *item in arrayOfRandomText) {
NSString *newItem = [item stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
[myAppendedStr appendString:[NSString stringWithFormat:@"%@<br/><br/>", newItem]];
}
NSMutableAttributedString *attrStr = [[NSMutableAttributedString alloc] initWithData:[myAppendedStr dataUsingEncoding:NSUnicodeStringEncoding] options:@{ NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType } documentAttributes:nil error:nil];
[attrStr addAttribute:NSForegroundColorAttributeName value:[UIColor blackColor] range:NSMakeRange(0,attrStr.length)];
[attrStr addAttribute:NSFontAttributeName value:[UIFont fontWithName:@"Helvetica Neue" size:14.0] range:NSMakeRange(0, attrStr.length)];
self.myTxtView.attributedText = attrStr;