Ios 用于长文本的2行(多行)选择器

Ios 用于长文本的2行(多行)选择器,ios,picker,Ios,Picker,为什么我可以为选择器设置行高或多行, 问题是我的选择器有很长的文本,或者在选择器中出现换行。。。xcode 5。。。 我从数组中获取选择器的值。 我的自定义选择器的代码是: - (UIView *)pickerView:(UIPickerView *)pickerView viewForRow:(NSInteger)row forComponent:(NSInteger)component reusingView:(UIView *)view{ UILabel *label = [[U

为什么我可以为选择器设置行高或多行, 问题是我的选择器有很长的文本,或者在选择器中出现换行。。。xcode 5。。。 我从数组中获取选择器的值。 我的自定义选择器的代码是:

- (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;
}

感谢您的帮助

因为您正在创建标签,您可以尝试UILabel的以下属性:

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

如果您设置了
label.numberOfLines=0
,您应该能够在标签中放置任意数量的行。

UILineBreakModeWordWrap
在iOS 6.0中不推荐使用

textLabel.lineBreakMode = NSLineBreakByWordWrapping;  
textLabel.numberOfLines = 0;
试试这个代码

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


尝试添加“label.numberOfLines=2”。label.numberOfLines=2。我已经试过了,但没有成功。如果你稍微减小字体大小,或者标签使用更大的高度,会发生什么?@Heisenberg保留行
label.numberOfLines=2
,然后尝试将框架设置为标签(你正在创建框架,但没有将其设置为标签)。创建边框时应考虑字体的高度(
CGRectMake(0,0265,font.lineHeight*2
)当我减小字体大小时,竞争文本在一行中,这看起来不太好…如何更改高度?
- (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;
}