Reputation: 107
I have used a popoverPresentationController on iOS Swift and i have put both an image and text in the popover?
The issue i am having is that the content is too big for the popover? is it possible to set the dimensions?
Pictures are below of both the issue i am having and the trial code and error message?
let myAlert = UIAlertController(title: "\n\n\n\n\n\n", message: "Correct answer selected, move on to next level", preferredStyle: UIAlertControllerStyle.actionSheet)
let okAction = UIAlertAction(title: "Ok", style: UIAlertActionStyle.default)
{
// action in self.dismiss(animated: true, completion: nil)
action in self.performSegue(withIdentifier: "goSegue1", sender: self)
self.musicEffect.stop()
}
// put image into action sheet
let imageView = UIImageView(frame: CGRect(x: 70, y: -30, width: 140, height: 140))
imageView.image = #imageLiteral(resourceName: "wellDone2.png")
myAlert.addAction(okAction);
myAlert.view.addSubview(imageView)
// display the alert messgae
myAlert.popoverPresentationController?.sourceView = view
myAlert.popoverPresentationController?.sourceRect = (sender as AnyObject).frame
myAlert.preferredContentSize = CGSize(width: 500, height: 800)
Upvotes: 0
Views: 972
Reputation: 10512
The size of the popover is not controlled by the PopoverPresentationController
. The PopoverPresentationController
only specifies how to present content, but the content itself, including size, is set by the view from which you have obtained the controller, in your case myAlert
.
You have the right idea trying to set preferredContentSize
, but you're setting it on the wrong view. You should change the line
popoverPresentationController?.preferredContentSize = /* ... */
to:
myAlert.preferredContentSize = /* ... */
This should solve the problem.
Upvotes: 5