为什么我可以为选择器设置行高或多行, 问题我有我的选择器的长文本,或者在选择器中给出一个换行符... xcode 5 ... 我从数组中获取选择器的值。 我的自定义Picker的代码是:
- (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;
}
感谢您的帮助
答案 0 :(得分:2)
试试此代码
- (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;
}
答案 1 :(得分:1)
因为您正在创建标签,所以您可以尝试使用UILabel的这个属性:
// UILabel wraps text across multiple lines
label.lineBreakMode = UILineBreakModeWordWrap;
如果设置label.numberOfLines = 0
,您应该可以在标签中放置任意数量的行。
答案 2 :(得分:0)
UILineBreakModeWordWrap
textLabel.lineBreakMode = NSLineBreakByWordWrapping;
textLabel.numberOfLines = 0;