I have a UIPickerView displayed inside a UIPopoverController. The dimensions of the UIPickerView are: 320x216. For some reason, the UIPickerView seems to be ~3/5 of the proper height, and the UIPopoverController spans all the way down to the bottom of the screen.
Please see the code below.
Thanks!
self.picker = [[[UIPickerView alloc] initWithFrame:CGRectMake(0, self.view.bounds.size.height+44, 320, 216)] autorelease];
self.picker.backgroundColor = [UIColor clearColor];
self.picker.showsSelectionIndicator = YES;
self.picker.delegate = self;
self.picker.dataSource = self;
self.picker.transform = CGAffineTransformMakeScale(-1, 1);
UIViewController *pickerController = [[UIViewController alloc] init];
[pickerController setView:self.picker];
UIPopoverController *pickerPopover = [[UIPopoverController alloc] initWithContentViewController:pickerController];
[pickerPopover presentPopoverFromBarButtonItem:sender permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
pickerPopover.delegate = self;
self.popover = pickerPopover;
[pickerController release];
[pickerPopover release];
The reason for the “squashed” picker view seems to be this line:
Instead, add the picker view as a subview:
Next, to fix the popover height, set
popoverContentSizebefore presenting it:Also, fix the picker view’s frame from this:
to this: