Reputation: 24426
What would be the best way to create a UIPicker with only two wheels: a date and a time, like so:
Fri 5 June | 15:30
Sat 6 June | 15:35 < Selected
Sun 7 June | 15:40
The dates would go back and forward 7 days, and the time would also include a 'Now'.
Upvotes: 2
Views: 1986
Reputation: 2589
The API does not provide a way to do this. You can make a pretty convincing replica yourself using a UIPickerView rather than using UIDatePicker.
As the UIDatePicker or UIPickerView don't have the UI_APPEARANCE_SELECTOR and even you can't change UIDatePicker contents' appearance as its UIControl and not having any delegate so it has its native appearance whereas in case of UIPickerView you can change its contents' appearance similar as in UITableView.
Check out this link having same scenario like you have Custom iOS UIDatepicker using UIAppearance
Upvotes: 0
Reputation: 1649
you can do so by using UIPickerViewDelegate Method like :
- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component
also go through this tutorial which explains ow to implement a multicomponent UIPicker .. hope its helpful
Upvotes: 1
Reputation: 720
first of make a UIPickerview and the delegate of Pickerview will be like this -
- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView
{
return 2;
}
- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:
(NSInteger)component
{
if (component == 0)
{
return [arr_Date count];
}
else
{
return [arr_Time count];
}
}
- (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row
forComponent:(NSInteger)component
{
if (component == 0)
{
return [arr_date objectAtIndex:row];
}
else
{
return [arr_Time objectAtIndex:row];
}
}
And for date include 7 dates in your arr_date.
Upvotes: 2