JerrySLKylo
JerrySLKylo

Reputation: 33

How to set popover view anchor programmatically with Swift 3.0

I was trying to set the presentation of a segue in storyboard to be "Present as popover", and it requires me to add an anchor to it. I have set up a button with code so I could not drag to set the anchor to be that button in storyboard. How can I set the anchor programmatically?

Upvotes: 3

Views: 2527

Answers (1)

estoril
estoril

Reputation: 115

A UIPopoverPresentationController which creates a popover needs an anchor point either by specifying it to barButtonItem: UIBarButtonItem?, a sourceView: UIView?, or a sourceRect:CGRect.

In your case, you will be applying sourceView: UIView? to the button that you created programatically after initializing your popover...

popover.sourceView = myButton

Upvotes: 3

Related Questions