I've customized a Popover creating an subclass of UIPopoverBackgroundView
in the following way:
class CustomPopoverBackgroundView: UIPopoverBackgroundView {
override var arrowOffset: CGFloat {
get{
return self.arrowOffset
}
set{
}
}
override var arrowDirection: UIPopoverArrowDirection {
get {
return UIPopoverArrowDirection.Up
}
set {
}
}
override init(frame: CGRect) {
super.init(frame: frame)
backgroundColor = UIColor(red: 0.19, green: 0.19, blue: 0.19, alpha: 1.0)
var arrowView = UIImageView(image: UIImage(named: "12_24_pop_black"))
arrowView.frame = CGRect(x: 17.0, y: -11.0, width: 24.0, height: 12.0)
self.addSubview(arrowView)
}
required init(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
override class func wantsDefaultContentAppearance() -> Bool {
return false
}
override class func contentViewInsets() -> UIEdgeInsets{
return UIEdgeInsets(top: 0.0, left: 0.0, bottom: 0.0, right: 0.0)
}
override class func arrowHeight() -> CGFloat {
return 0.0
}
override class func arrowBase() -> CGFloat{
return 24.0
}
}
I do this mainly because I want to create a popover without the rounded borders by default that Apple provides.
The problem is that inside the Popover I've a View
with a gray color and I don't know why the ViewController
is not expanded completely and I can see the borders of the color of the background that I set above in code (black).
Something like this picture of the Popover open :
I know that you could load borders for the Popover, but in my case I would change the background color of the View in some cases.
What I want to do is expand the ViewController
displayed as Popover to avoid rounded corners, or I don't know maybe exist a better solution.
How could solve this problem ?
Thanks in advance
You can solve this issue by overriding de following method in the Popover controller
override func viewWillAppear(animated: Bool)
{
super.viewWillAppear(animated)
self.view.superview?.layer.cornerRadius = 0
}