Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UIDatePicker customization

I have customized UIDatePicker to a level and I am adding it to UIAlertView.

enter image description here

but I am getting a black color on the bottom and the top of date picker, how to remove it. I want the date picker to be neat and clean.

The code I use to achieve this:

UIDatePicker *datePicker = [[UIDatePicker alloc] init];
datePicker.frame=CGRectMake(20, 45.0, 240.0, 150.0);
datePicker.minimumDate=[NSDate date];

//Forget about this logic.

NSString *alertTitleString=@"";
if(self.presentingViewController !=nil)
{
    alertTitleString=@"Select Date and Time";
    [datePicker setDatePickerMode:UIDatePickerModeDateAndTime];
}
else
{
    alertTitleString=@"Select Time";
    [datePicker setDatePickerMode:UIDatePickerModeTime];

}
[datePicker setDate:[NSDate date]];

UIView *view = [[datePicker subviews] objectAtIndex:0];
[view setBackgroundColor:[UIColor clearColor]]; // hide the first and the last subviews
[[[view subviews] objectAtIndex:0] setHidden:YES];
[[[view subviews] lastObject] setHidden:YES];



 UIAlertView *eventStartDateAlert = [[UIAlertView alloc] initWithTitle:alertTitleString message:@"\n\n\n\n\n\n\n\n" delegate:self cancelButtonTitle:NSLocalizedString(@"OK", @"Ok") otherButtonTitles:nil];
eventStartDateAlert.delegate = self;
[eventStartDateAlert addSubview:datePicker];
[eventStartDateAlert show];
like image 231
Satheesh Avatar asked Nov 13 '22 06:11

Satheesh


1 Answers

Basically what you want to do, is to remove the gradient on top and bottom, right?

This is going to work, at least for iOS 5 and 6.

[view.subviews[5]  setHidden:YES];
[view.subviews[11] setHidden:YES];
[view.subviews[17] setHidden:YES];
like image 109
Camo Avatar answered Nov 15 '22 06:11

Camo