为什么我可以为选择器设置行高或多行, 问题是我的选择器有很长的文本,或者在选择器中换行... 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;
}
感谢帮助
最佳答案
试试这段代码
- (CGFloat)pickerView:(UIPickerView *)pickerView rowHeightForComponent:(NSInteger)component{
return 50;
}
然后
- (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;
}
关于ios - 2 行(多行)长文本选择器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23435751/