I want a popover without rounded corners and with no arrow.
I have done the following code but it did not work:
//SerachPopViewController.swift
//MARK: InitCoder
required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
//popover settings
//popoverPresentationController!.permittedArrowDirections = .Any
modalPresentationStyle = .Popover
popoverPresentationController!.delegate = self
//permittedArrowDirections = UIPopoverArrowDirection(rawValue: 0)
self.preferredContentSize = CGSize(width:340,height:380)
}
//QueryTableViewController.swift
@IBAction func searchFilter(sender: AnyObject) {
let searchPopController = storyboard!.instantiateViewControllerWithIdentifier("SerachPopViewController") as! SerachPopViewController
searchPopController.serachPopDelegate = self
searchPopController.modalPresentationStyle = .Popover
searchPopController.preferredContentSize = CGSize(width:340,height:380)
let popoverPresentationController = searchPopController.popoverPresentationController
popoverPresentationController!.sourceView = self.view;
popoverPresentationController!.sourceRect = CGRectMake(CGRectGetMidX(self.view.bounds), CGRectGetMidY(self.view.bounds),0,0)
popoverPresentationController!.permittedArrowDirections = UIPopoverArrowDirection();
self.presentViewController(searchPopController, animated: true, completion: nil)
}
I am able to display popover view with arrow and rounded arrow.
Please help me to achieve:
I was not 100% happy with shawnynicole's answer because I realized the change from the rounded to the rectangular corners are notable/visible.
So I came up with this: subclass the view controller (in my case it was an UINavigationController
) and override viewDidLayoutSubviews
and update corners there. This is better because corners change animation is not visible and it will be updated every time needed (on rotations, etc).
It works in iOS11 and probably should work on others versions too.
class PopoverNavigationController: UINavigationController {
@IBInspectable var cornerRadius: Int = -1
override func viewDidLayoutSubviews() {
super.viewDidLayoutSubviews()
let r = CGFloat(cornerRadius)
if r >= 0 && view.superview?.layer.cornerRadius != r {
view.superview?.layer.cornerRadius = r
}
}
}