2016-03-16 55 views

回答

2

一套符合你的UITextView的數量爲0。 在控制器中包含的tableView使用viewDidLoad中:

tableView.estimatedRowHeight = 55.0 
tableView.rowHeight = UITableViewAutomaticDimension 
+0

如果您的文字很大,您可能必須使用高於55的'estimatedRowHeight'。 – Koen

+0

是的,這個值取決於你在UITableViewCell中擁有的值 – Ro22e0

2

要計算你的TextView的高度,我想你需要知道的高度文本。所以,在你的heightForRowAtIndexPath委託方法,計算文本高度和使用其返回此:

func heightWithConstrainedWidth(width: CGFloat, font: UIFont) -> CGFloat { 
    let constraintRect = CGSize(width: width, height: CGFloat.max) 

    let boundingBox = self.boundingRectWithSize(constraintRect, options: NSStringDrawingOptions.UsesLineFragmentOrigin, attributes: [NSFontAttributeName: font], context: nil) 

    return boundingBox.height 
} 

您需要設置TextView的約束,底部,頂部,開頭和結尾的爲0,所以他們適應的大小細胞。 該代碼被拍下from here

相關問題