2015-03-13 61 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列的寬度工作,使他們稍微大一點,直到數字排隊