我通过以下方式自定义了一个 Popover,创建了 UIPopoverBackgroundView
的子类:
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
}
}
我这样做主要是因为我想创建一个没有苹果默认提供的圆角边框的弹出窗口。
问题是,在 Popover 内部,我有一个灰色的 View
,我不知道为什么 ViewController
没有完全展开,我可以看到我在上面的代码中设置的背景颜色的边框(黑色)。
像这张弹出窗口打开的图片:
我知道您可以加载 Popover 的边框,但就我而言,在某些情况下我会更改 View 的背景颜色。
我想要做的是扩展显示为 Popover 的 ViewController
以避免圆角,或者我不知道是否存在更好的解决方案。
如何解决这个问题?
提前致谢
最佳答案
您可以通过重写 Popover Controller 中的以下方法来解决此问题
override func viewWillAppear(animated: Bool)
{
super.viewWillAppear(animated)
self.view.superview?.layer.cornerRadius = 0
}
关于swift - 使用 UIPopoverBackgroundView 自定义的 Popover 中的边框问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28439027/