【发布时间】:2015-02-10 18:25:34
【问题描述】:
我自定义了一个 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
}
}
我这样做主要是因为我想创建一个没有 Apple 提供的默认圆角边框的弹出框。
问题是在 Popover 里面我有一个灰色的 View,我不知道为什么 ViewController 没有完全展开,我可以看到我的背景颜色的边界上面用代码设置(黑色)。
类似于这张 Popover 打开的图片:
我知道您可以为 Popover 加载边框,但在我的情况下,我会在某些情况下更改 View 的背景颜色。
我想要做的是扩展显示为 Popover 的 ViewController 以避免圆角,或者我不知道是否存在更好的解决方案。
如何解决这个问题?
提前致谢
【问题讨论】: