Actualmente estoy trabajando en un programa que rellena dinámicamente una vista del selector desde mi configuración de Core Data. Tengo todo funcionando en lo que respecta a los datos, pero el problema que me estoy encontrando ahora es formatear en mis etiquetas.UIPickerView con Multiline UILabel
El selector se presenta con su propia barra de herramientas en una hoja de acción con un botón en el lado derecho de la barra de herramientas. Su estado inicial es con 2 diales visibles. cuando se presiona el botón, cambia a 3 diales.
- (UIView *)pickerView:(UIPickerView *)pickerView viewForRow:(NSInteger)row forComponent:(NSInteger)component reusingView:(UIView *)view
{
UILabel *pickerLabel = (UILabel *)view;
CGSize limitSize = CGSizeMake(100.0f, 45.0f);
CGSize textSize;
CGRect labelRect;
NSString *title = @"";
switch (numberOfComponents){
case 2:
{
...gets strings from fetched data (varying length from 4 to 20+)
title = someString
}
case 3:
{
...same as above but for the second set of data.
title = someString
}
}
textSize = [title sizeWithFont:[UIFont systemFontOfSize:14] constrainedToSize:limitSize lineBreakMode:UILineBreakModeWordWrap];
labelRect = CGRectMake(0, 0, textSize.width, textSize.height);
NSLog(@"length:%i title:%@",[title length],title);
NSLog(@"h:%f w:%f",textSize.height,textSize.width);
if (pickerLabel == nil)
{
pickerLabel = [[[UILabel alloc] initWithFrame:labelRect] autorelease];
[pickerLabel setFont:[UIFont systemFontOfSize:14]];
[pickerLabel setBackgroundColor:[UIColor clearColor]];
[pickerLabel setLineBreakMode:UILineBreakModeWordWrap];
[pickerLabel setTextAlignment:UITextAlignmentCenter];
[pickerLabel setNumberOfLines:2];
}
[pickerLabel setText:title];
return pickerLabel;
}
he configurado manualmente la altura de la fila en 32.0f. Estoy obteniendo resultados muy extraños porque algunas de las etiquetas del segundo componente funcionan a la perfección. pero otros no se ajustan en absoluto, y algunos simplemente se muestran como espacios en blanco.
es decir: coles de Bruselas se envuelve bien (componente derecho). pero Milk and Cream no muestra (solo la leche es visible) verduras no aparece en absoluto. ¿Dónde me estoy equivocando en mi código?
Gracias, esto realmente me ayudó. –