Question

why can i set the Row hight or multi lines for a picker, the problem i have long texts for my picker, or gives an line break in picker... xcode 5 ... i get the values for the picker from an array. my code for my custom Picker is:

- (UIView *)pickerView:(UIPickerView *)pickerView viewForRow:(NSInteger)row forComponent:(NSInteger)component reusingView:(UIView *)view{

    UILabel *label = [[UILabel alloc] init];
    CGRect frame = CGRectMake(0,0,265,40);
    label.backgroundColor = PickColor;
    label.textColor = [UIColor whiteColor];
    label.font = [UIFont fontWithName:@"HelveticaNeue-Bold" size:18 ];
    label.textAlignment = NSTextAlignmentCenter;



    if(component == 0)
    {
        label.text = [_vergehen objectAtIndex:row];
    }
        return label;
}

thanks for help

Was it helpful?

Solution 2

Because you're creating a label, you might try this property of UILabel:

// UILabel wraps text across multiple lines
label.lineBreakMode = UILineBreakModeWordWrap;

If you set label.numberOfLines = 0, you should be able to get any number of lines placed within the label.

OTHER TIPS

Try this code

- (CGFloat)pickerView:(UIPickerView *)pickerView rowHeightForComponent:(NSInteger)component{
  return 50;
}

then

- (UIView *)pickerView:(UIPickerView *)thePickerView viewForRow:(NSInteger)row forComponent:(NSInteger)component reusingView:(UIView *)view
{
   UILabel *lblTitle = [[UILabel alloc] initWithFrame:CGRectMake(5, 0, 310, 50)];
   lblTitle.numberOfLines=2;
   lblTitle.textColor=[UIColor blackColor];
   lblTitle.font=[UIFont systemFontOfSize:14];
   lblTitle.text=[selectionList objectAtIndex:row];
   return lblTitle;
}

UILineBreakModeWordWrap is deprecated deprecated in iOS 6.0

textLabel.lineBreakMode = NSLineBreakByWordWrapping;  
textLabel.numberOfLines = 0;
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top