Skip to main content

UIPopoverController height

A recent project I worked on required a number of UIPopoverController screens. The api allows the implementation of these very easily in just a couple of lines as below:

Here i create a UIPopoverController when a button is pressed,  using the sender button to presentPopoverFromRect.

But what if you want to amend the size of the popover?

Well thats just as easy. Simply ass the following line before you present the popover:

There have been a couple of occastions though where I have wanted to clip the height of the popover to the UITableView height though that I was displaying in the popover. Maybe the table does not always have the same number of items in or displays different types of lists. Setting a static height here would not always look great.

The solution to this I used was amending the height of the UIPopoverController in the viewWillAppear function. I then set this controller’s preferedContentSize height to that of the UITableView

Of course you can use this method to set a static height also should wish.

 

Please follow and like us: