Continuous UIDatePicker Minutes

I set the UIDatepicker timeInterval to 30 minutes, so it shows it as 30.60 (repeats). I really don't want this to be repeated, just show 2 options (e.g. AM / PM). Is there a way to do this without creating it from scratch?

Thanks!

+4
source share
1 answer

Why aren't you using UIPicker instead?

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; } 
+1
source

Source: https://habr.com/ru/post/1391330/


All Articles