2011-05-20 16 views
6

Necesito insertar a UILabel texto de varias líneas. Hago lo siguiente:Multiline UILabel?

NSMutableString * spName = [[NSMutableString alloc ]initWithString:@""]; 

for (NSUInteger i=0; i<arrEx.count; ++i) 
{ 
    ExInfo * exInf = [arrEx objectAtIndex:i]; 
    [spName appendString:[MyObject getName:exInf.spNum]]; 
    [spName appendString:@" "]; 
    [spName appendString:exInf.totalTime]; 
    [spName appendString:@"\n"];   
} 

CGSize size = [spName sizeWithFont:[UIFont systemFontOfSize:14] 
       constrainedToSize:constraint 
        lineBreakMode:UILineBreakModeWordWrap]; 

[cell.exsInfoLabel setFrame:CGRectMake(CELL_CONTENT_MARGIN, top, CELL_CONTENT_WIDTH - (CELL_CONTENT_MARGIN * 2), size.height)]; 
[cell.exsInfoLabel setText:spName]; 
[spName release]; 

arrEx se compone de dos elementos, por lo que debería haber dos cadenas. Pero el UITableViewCell contiene solo la primera cadena. En IB, configuré el recuento de líneas en 0 para UILabel cell.exsInfoLabel.

Respuesta

10

probar esto:

CGSize labelsize; 
UILabel *commentsTextLabel = [[UILabel alloc] init]; 
[commentsTextLabel setNumberOfLines:0]; 
[commentsTextLabel setBackgroundColor:[UIColor clearColor]]; 
NSString *text = @"yourtextString"; 
[commentsTextLabel setFont:[UIFont fontWithName:@"Helvetica"size:14]]; 
labelsize = [text sizeWithFont:commentsTextLabel.font 
      constrainedToSize:CGSizeMake(268, 2000.0) 
       lineBreakMode:UILineBreakModeWordWrap]; 
commentsTextLabel.frame = CGRectMake(10, 24, 268, labelsize.height); 
[cell.contentView addSubview:commentsTextLabel]; 
[commentsTextLabel release]; 
+0

modifique el marco de acuerdo a sus necesidades. – Gypsa

+0

Hola, he intentado establecer setNumberOfLines en 0. Y no nos funciona, ¿entiendo tu publicación? –

+5

número de líneas 0 significa que puede agregar un número infinito de líneas. la documentación de apple dice que: -Esta propiedad controla el número máximo de líneas que se usarán para ajustar el texto de la etiqueta en su rectángulo delimitador. El valor predeterminado para esta propiedad es 1. Para eliminar cualquier límite máximo y usar tantas líneas como sea necesario, establezca el valor de esta propiedad en 0. – Gypsa

2

probar antes setText:

cell.exsInfoLabel.numberOfLines = 2; 

O:

cell.exsInfoLabel.numberOfLines = arrEx.count; 
+0

Esto lamentablemente no funciona :( –