Set Multiple Arrow Directions on UIPopoverController in Swift
popoverController.permittedArrowDirections = [.up, .down]
Set Multiple Arrow Directions on UIPopoverController in Swift
popoverController.permittedArrowDirections = [.up, .down]
Set UIPopover arrow direction and position manually
Set the direction for the popover using:
[yourPopover setPopoverArrowDirection: UIPopoverArrowDirectionDown];
You can also use UIPopoverArrowDirectionUp
, UIPopoverArrowDirectionLeft
, and UIPopoverArrowDirectionRight
, and UIPopoverArrowDirectionAny
.
For Swift
yourPopover?.permittedArrowDirections = .up // or .down, .left, .right
UIPopoverController permitted arrow directions issues
You need to use UIPopoverArrowDirectionDown
in this case. Since the button is in the bottom area of the view, if you want to show the popover below the button (that is what UIPopoverArrowDirectionUp
suggests implicitly), it doesn't have any space to show the pop over.
If you use UIPopoverArrowDirectionAny
, then iOS automatically figures out which way it can extend.
Present UIPopoverController in same position with changing just arrow offset
For my popover I wanted the arrow to be top-left instead of top-center (which is default).
I've managed to get the result below (screenshot) by setting the popoverLayoutMargins
property of the UIPopoverController. You can use it to reduce the screen-area used in the internal calculations of the UIPopoverController to determine where to show the popover.
The code:
// Get the location and size of the control (button that says "Drinks")
CGRect rect = control.frame;
// Set the width to 1, this will put the anchorpoint on the left side
// of the control
rect.size.width = 1;
// Reduce the available screen for the popover by creating a left margin
// The popover controller will assume that left side of the screen starts
// at rect.origin.x
popoverC.popoverLayoutMargins = UIEdgeInsetsMake(0, rect.origin.x, 0, 0);
// Simply present the popover (force arrow direction up)
[popoverC presentPopoverFromRect:rect inView:self.view permittedArrowDirections:UIPopoverArrowDirectionUp animated:YES];
I think you'll be able to get the desired result by tweaking the above.
UIPopover without any arrows
Yes it is possible just do:
[self.popoverController presentPopoverFromBarButtonItem:anItem
permittedArrowDirections:0
animated:YES];
The zero represent no direction.
Related Topics
Why Do I Have to Explicitly Unwrap My String in This Case
Access Parent Project Other_Swift_Flags from Pod
Alamofire Post Request with JSON Encoding
Swift - Boundingbox Cause Exc_Bad_Access (Code=1)
Swift: Nested Optionals in a Single Guard Statement
How to Create a Single Page Vertical Scrolling Pdfview in Swift
Uicolor Code in a Variable in Swift
Audiokit - Temporary File Size Is Too Big
How to Observe Object's Property in Rxswift
Dictionary of a Protocol Swift 4
Detecting End of The Playback in Avaudioplayer
Xcode 9.2 Is Not Showing Swift 4.1
How to Convert Custom Object to Data Swift
How to Make Nsbutton Title at Bottom and Centered
Scenekit - Why Scnlight Created Automatically in Scnscene
Filter Array of Objects with Multiple Criteria and Types in Swift