2011-08-30 11 views
9

¿Cómo hago una UITextView ampliar o reducir el tamaño del texto en su interior y luego hacer la UIScrollView ampliar o reducir para adaptarse a la UITextViewUITextView Altura automática

+0

Parece que debería poder hacer lo que intenta hacer usando - [UIView sizeToFit]. Eche un vistazo a los documentos de la clase UIView y vea si eso es lo que está buscando. Un código de muestra ayudaría a aclarar exactamente lo que está intentando. –

Respuesta

26
CGRect frame; 
frame = textiew.frame; 
frame.size.height = [textView contentSize].height; 
textView.frame = frame; 

Una cosa a tener en cuenta es que la correcta contentSize solo está disponible después de, el UITextView se ha agregado a la vista con addSubview y se le ha asignado el texto. Antes de eso, es igual a frame.size

+8

textView contentSize no parece hacer nada. – Rollo

+0

¿Eso se simplifica a 'cell.commentLabel.frame.size.height = cell.commentLabel.contentSize.height' en Swift? – User

+0

@Darksinge se aprecia su esfuerzo por actualizar el código de Swift 2.0, pero debe publicarlo como su propia respuesta. –

Cuestiones relacionadas