2012-01-16 93 views
4

我將我的UIDatepicker timeInterval設置爲30分鐘,因此它顯示爲30,60(重複)。我真的不希望它重複,只顯示2個選項(如AM/PM)。有沒有辦法做到這一點,而不是從頭開始創建它?UIDatePicker非連續分鐘

謝謝!

+1

同樣的問題在這裏..沒有人有答案? – 2012-05-11 19:29:23

+0

我無法做到這一點。我只是沒有重寫它,因爲它會花費太多時間。 – user754905 2012-05-11 20:08:24

回答

1

爲什麼不使用UIPicker呢?

UIPickerView *pick=[[UIPickerView alloc] initWithFrame:CGRectMake(300, datep.frame.origin.y, datep.frame.size.width, datep.frame.size.height)]; 
[pick setDelegate:self]; 
[pick setDataSource:self]; 
[pick setShowsSelectionIndicator:YES]; 
[self.view addSubview:pick]; 

- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView{ 
return 3; 
} 
- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component{ 
if(component==0){ 
    return 12; 
}else{ 
    return 2; 
} 

return 2; 
} 

- (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component{ 
if(component==1){ 
    if(row==1) 
     return @"30"; 
    else 
     return @"00"; 
    } 
else if(component==0){ 
    return [NSString stringWithFormat:@"%d", row+1]; 
}else{ 
    if(row==1) 
     return @"AM"; 
    else 
     return @"PM"; 
    }  
} 

-(CGFloat)pickerView:(UIPickerView *)pickerView widthForComponent:(NSInteger)component{ 
return 50; 
} 

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