UIPopover without any arrows

UikitIpadUipopovercontroller

Uikit Problem Overview


Is it possible to present a popover without any sort of arrows pointing somewhere?

Uikit Solutions


Solution 1 - Uikit

Yes it is possible just do:

 [self.popoverController presentPopoverFromBarButtonItem:anItem   
                                permittedArrowDirections:0
                                                animated:YES];

The zero represent no direction.

Solution 2 - Uikit

For iPhone and swift 2.0 try this one

Code to initiate popover

initiatePopover(){
    let popoverContent = self.storyboard?.instantiateViewControllerWithIdentifier("XYZController") as! XYZController
    let nav = UINavigationController(rootViewController: popoverContent)
    nav.modalPresentationStyle = UIModalPresentationStyle.Popover
    let popover = nav.popoverPresentationController
    popoverContent.preferredContentSize = CGSizeMake(250 ,200)
    popover!.delegate = self
    popover!.sourceView = self.view
    popover!.sourceRect = CGRectMake(200,200,0,0)
    popover!.permittedArrowDirections = UIPopoverArrowDirection(rawValue: 0)
    self.presentViewController(nav, animated: true, completion: nil)
}

And add this to your ViewController

func adaptivePresentationStyleForPresentationController(controller: UIPresentationController) -> UIModalPresentationStyle {
    return UIModalPresentationStyle.None
}

Solution 3 - Uikit

Swift4:

popover.permittedArrowDirections = []              

Solution 4 - Uikit

Set the permittedArrowDirections to 0.

permittedArrowDirections:0

Code -

[self.popoverController presentPopoverFromBarButtonItem:anItem   
                                permittedArrowDirections:0
                                                animated:YES];

Zero tells "NoDirection".

Solution 5 - Uikit

Swift3, this code work for me

popover.permittedArrowDirections = .init(rawValue: 0)

Solution 6 - Uikit

For Swift 2.0 and iOS9 the solution is:

popoverViewController?.permittedArrowDirections = UIPopoverArrowDirection()

Solution 7 - Uikit

In Swift, you can simply do:

popoverPresentationController.permittedArrowDirections = []

Since in another configuration you could have used:

popoverPresentationController.permittedArrowDirections = [.up, .down]

Solution 8 - Uikit

Try this , it works for me.

[self.popoverViewController presentPopoverFromRect:rect inView:self.view  permittedArrowDirections:0 animated:YES];

Solution 9 - Uikit

In swift 3, you can build a UIPopoverArrowDirection extension for this:

extension UIPopoverArrowDirection {
    public static var noArrow: UIPopoverArrowDirection {
        return UIPopoverArrowDirection(rawValue: 0)
    }
}

and the you can do:

popoverPresentationController!.permittedArrowDirections = .noArrow

Solution 10 - Uikit

This works fine for me.

[popoverController presentPopoverFromRect:CGRectMake(0, 0, 20, 20)
                                    inView:self.view 
                  permittedArrowDirections:NULL 
                                  animated:YES];

Enjoy Coding.

Solution 11 - Uikit

In my case for swift developers

popoverController.sourceView = self.view
popoverController.sourceRect = self.view.bounds
popoverController.backgroundColor = UIColor.brownColor()

popoverController.permittedArrowDirections = UIPopoverArrowDirection.init(rawValue: 0)
popoverController.sourceRect = CGRectMake(width/4, hieght/4, width/2, hieght/2);

Solution 12 - Uikit

Nope, there is no UIPopoverArrowDirectionNone option, and UIPopoverArrowDirectionUnknown throws an exception i think if you try to use that to present.

Instead of a popover controller, you can call presentModalViewController:animated: and set the controller you are presenting to have a modal presentation style of UIModalPresentationFormSheet or perhaps UIModalPresentationPageSheet. Those are more traditional popup screens than popovers are.

Solution 13 - Uikit

Do not use Popovers if you don't want to show arrows. Present your view controller as a Modal and use a UIModalPresentationFormSheet instead.

Example:

UIStoryboard *sb = [UIStoryboard storyboardWithName:@"MyStoryBoard" bundle:nil];
UIViewController* viewController = [sb instantiateViewControllerWithIdentifier:@"myViewController"];
viewController.modalPresentationStyle = UIModalPresentationFormSheet;
[presenterViewController presentViewController: viewController animated:YES completion:^{
    
}];

Solution 14 - Uikit

Try this one

[popOverController presentPopoverFromRect:CGRectMake(0, 0, 30, 40) inView:popOverContentView permittedArrowDirections:0 animated:NO];

Solution 15 - Uikit

I use popover to show menu depending on touch coordinate. In this case popover uses maximum height of self.view

CGRect popeverFrame = CGRectMake(touchPoint.x, touchPoint.y, 0, 0);
[self.popover presentPopoverFromRect:popeverFrame
                              inView:self.view
            permittedArrowDirections:UIPopoverArrowDirectionAny
                            animated:YES];

But when I use 0-direction. Popover rectangle doesn't set it height to maximum and can only be set by appropriate property.

CGRect popeverFrame = CGRectMake(touchPoint.x, touchPoint.y, 0, 0);
[self.popover presentPopoverFromRect:popeverFrame
                              inView:self.view
            permittedArrowDirections:UIPopoverArrowDirectionAny
                            animated:YES];

Hope this will help: https://stackoverflow.com/questions/6770987/help-with-uipopovercontroller-size

Solution 16 - Uikit

To make a pop over direction none and make it to appear in center of the view controller :

let PopSrnVar = popoverPresentationController
let ConRctVar = view.frame
PopSrnVar!.sourceRect = CGRectMake(ConRctVar.width/4, ConRctVar.height/4, ConRctVar.width/2, ConRctVar.height/2)
// To make arrows as none
PopSrnVar!.permittedArrowDirections = UIPopoverArrowDirection()

Solution 17 - Uikit

A simple solution in SWIFT:

popover!.permittedArrowDirections = nil

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionDavid LiuView Question on Stackoverflow
Solution 1 - UikitMattView Answer on Stackoverflow
Solution 2 - UikitSachin AgarwalView Answer on Stackoverflow
Solution 3 - UikitAlexey MalyarenkoView Answer on Stackoverflow
Solution 4 - UikitAkshayView Answer on Stackoverflow
Solution 5 - UikitKhuongView Answer on Stackoverflow
Solution 6 - UikitNuno VieiraView Answer on Stackoverflow
Solution 7 - UikitTomnView Answer on Stackoverflow
Solution 8 - UikitsureshView Answer on Stackoverflow
Solution 9 - UikitmanueGEView Answer on Stackoverflow
Solution 10 - UikitKundanView Answer on Stackoverflow
Solution 11 - UikitAsim KhanView Answer on Stackoverflow
Solution 12 - UikitKevlarView Answer on Stackoverflow
Solution 13 - UikitfedtuckView Answer on Stackoverflow
Solution 14 - UikitMouzmiSadiqView Answer on Stackoverflow
Solution 15 - UikitGxocTView Answer on Stackoverflow
Solution 16 - UikitSujay U NView Answer on Stackoverflow
Solution 17 - UikitBlankView Answer on Stackoverflow