Cómo evitar el truncamiento de texto con UITableViewCellStyleValue2

I use this code to make my UITableViewCells

cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue2 reuseIdentifier:CellIdentifier] autorelease];

If you're unfamiliar with UITableViewCellStyleValue2, the main text is shown, and then the detail text is shown after it, generally in a different color. However, when I do this, my main text is truncated, if it is longer than a short word. I want to force it to not truncate the main text and show the entire main text, and then the detail text after it. How can I do that?

preguntado el 09 de enero de 11 a las 04:01

2 Respuestas

You'll have to subclass UITableViewCell. You will need to override the layoutSubviews method to adjust the text label frames as needed. I'm not sure if you will be able to do this using the standard textLabel y detailTextLabel properties -- you might have to create your own text labels instead of using those properties.

Respondido el 09 de enero de 11 a las 07:01

I'm sorry, I am a beginner, but would you be able to provide a code example for this? I don't really understand how to adjust the bounds of the text labels. - Regan

This isn't exactly what you want, but you can make the text in the main label re-size as it gets longer. Set the minimumFontSize propiedad en el UILabel for the main text. That way if the text is too long, it will shrink the font until the minimum size before truncating it. If you need something more complicated, you'll probably have to make your own uiTableViewCell subclass and lay out your own labels with text sizes.

Respondido el 09 de enero de 11 a las 14:01

minimumFontSize already defaults to 0. You also have to set adjustsFontSizeToFitWidth to enable shrinking. The cell is vertically centered, so setting baselineAdjustment a UIBaselineAdjustmentAlignCenters is a good idea, too. - nschum

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.