我有一个带有UITextView的自定义单元格,单元格高度正在被切断

时间:2015-05-21 16:28:29

标签: ios objective-c layout uitextview

似乎只有在单词换行到下一行时才会发生,但如果我做了一个没有自动换行的列表,它会正确显示高度(例如:

@"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;

0 个答案:

没有答案