2015-03-13 60 views
0

我正在创建一个自定义时间选择器,使用this问题作为指南,我的列不排队。UIPickerView居中的列

enter image description here

这里是我创建的小时和分钟标签:

UILabel *hourLabel = [[UILabel alloc] initWithFrame:CGRectMake(datePickerCell.pickerView.frame.size.width/2 - 25, datePickerCell.pickerView.frame.size.height/2 - 15, 50, 30)]; 
      hourLabel.text = @"hour"; 
      [datePickerCell.pickerView addSubview:hourLabel]; 

      UILabel *minsLabel = [[UILabel alloc] initWithFrame:CGRectMake(datePickerCell.pickerView.frame.size.width - 25, datePickerCell.pickerView.frame.size.height/2 - 15, 50, 30)]; 
      minsLabel.text = @"min"; 
      [datePickerCell.pickerView addSubview:minsLabel]; 

这里是我的viewForRow:

- (UIView *)pickerView:(UIPickerView *)pickerView viewForRow:(NSInteger)row forComponent:(NSInteger)component reusingView:(UIView *)view 
{ 
    UILabel *columnView = [[UILabel alloc] initWithFrame:CGRectMake(pickerView.frame.size.width/4 - 15, 0, 35, 30)]; 
    columnView.text = [NSString stringWithFormat:@"%lu", row]; 
    columnView.textAlignment = NSTextAlignmentRight; 

    return columnView; 
} 

如何获得0与排队底部数字?

回答

2

尝试实施以下的委托方法:

- (CGFloat)pickerView:(UIPickerView *)pickerView widthForComponent:(NSInteger)component 

减少宽度到您需要的最小空间,他们应该排队更好,因为这样可以防止移动文本的左侧或右侧。还可以尝试将文本居中放置在1到2个字符之间,以强制事情保持一致。

+0

固定它的时候了。谢谢! – Siriss 2015-03-13 18:26:55

0

我认为它是你分配给pickerView的空间量,尝试与显示pickerView列的宽度工作,使他们稍微大一点,直到数字排队