easythrees
easythrees

Reputation: 1650

Can't change size for UIPopover?

I'm writing an app that needs to spawn a popover in order to add a new note. To that end, I have something that does kind of the trick, however, I can't seem to adjust the size of the popover. This is how I'm spawning it:

UIButton* btn =sender;
UIViewController* fooTroller = [[UIViewController alloc] init];

CGRect rectFoo = CGRectMake(0, 0, 100, 100);
UIView* fooView = [[UIView alloc] initWithFrame:rectFoo];
[fooView setBackgroundColor:[UIColor redColor]];
[fooTroller setView:fooView];
popOver =[[UIPopoverController alloc] initWithContentViewController:fooTroller];

[popOver presentPopoverFromRect:btn.frame
                         inView:self.view
       permittedArrowDirections:UIPopoverArrowDirectionLeft
                       animated:YES];

Any thoughts? It's not respecting the view size.

Upvotes: 1

Views: 712

Answers (1)

rmaddy
rmaddy

Reputation: 318774

You should not be calling setView: on the view controller. Let the view controller setup its own view.

The proper way to size a popover is to either override the contentSizeForViewInPopover method of your view controller to return the size or to set the popoverContentSize property on the popover.

UIButton* btn =sender;
UIViewController* fooTroller = [[UIViewController alloc] init];

popOver = [[UIPopoverController alloc] initWithContentViewController:fooTroller];
popOver.popoverContentSize = CGSizeMake(100, 100);

[popOver presentPopoverFromRect:btn.frame
                         inView:self.view
       permittedArrowDirections:UIPopoverArrowDirectionLeft
                       animated:YES];

Upvotes: 3

Related Questions