Set Multiple Arrow Directions on UIpopovercontroller in Swift

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.

UIPopovercontroller arrow on the left

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



Leave a reply



Submit