1
工作我有一個自定義單元格與下面的自動版式:自動版式+ heightForRowAtIndexPath/sizeWithFont無法正常
NSMutableArray *constraints = [NSMutableArray new];
[constraints addObjectsFromArray:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|-10-[descriptionLabel]-35-|" options:0 metrics:nil views:views]];
[constraints addObjectsFromArray:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|-10-[descriptionLabel]-10-|" options:0 metrics:nil views:views]];
[self.contentView addConstraints:constraints];
在我tableViewDelegate中,heightForRowAtIndexPath:
計算如下:
return [cell.descriptionLabel systemLayoutSizeFittingSize:UILayoutFittingCompressedSize].height + 20;
不幸的是,它在我的文本換行時不起作用 - 對於沒有換行的文本單元而言,它是正確的。我錯過了什麼?
你嘗試UILayoutFittingExpandedSize? – hybridcattt
是的,不會改變任何東西;它只適用於如果我設置preferredMaxLayoutWidth,但我不喜歡將其設置爲靜態數字... – swalkner