¿Cómo puedo ajustar la altura de UITableViewCell al contenido de UITextView que está dentro?
En mi storyboard tengo unUITableView
con generado dinámicamenteUITableViewCell
s. Cada celda contiene 2 etiquetas y 1 vista de texto:
Tengo un código que ajusta el tamaño del campo de texto a la cantidad de texto:
let fixedWidth = cell.myComment.frame.size.width
cell.myComment.sizeThatFits(CGSize(width: fixedWidth, height: CGFloat.max))
let newSize = cell.myComment.sizeThatFits(CGSize(width: fixedWidth, height: CGFloat.max))
var newFrame = cell.myComment.frame
newFrame.size = CGSize(width: max(newSize.width, fixedWidth), height: newSize.height)
cell.myComment.frame = newFrame;
y funciona bien, cuando configuro un color de fondo de mi textView en rojo veo:
y la celda en sí, estoy configurando el tamaño aquí:
func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat
{
if indexPath.row == 0 {
return 100//this is my static cell
}
else {
return 117; //for now it's hardcoded - how can I set this value dynamically based on content?
}
}
Entonces, como escribí en el comentario anterior, ¿cómo puedo establecer la altura de la celda dinámicamente en función de la cantidad de texto en la vista de texto?