我已经使用xib设计的自定义单元实现了UICollectionView
。现在,我尝试使selectedBackgroundView
大于原始cell
。
我尝试将单元格的clipsToBounds
更改为false(也是在绝望的内容视图中,背景视图,selectBackgroundView' s),但是没有效果。
是否可以拥有selectedBackgroundViewBigger
而不是单元格?
class MyCell: UICollectionViewCell {
static let nibName = "MyCell"
static let cellIdentifier = "MyCellIdentifier"
private var oneTimeSetup = false
@IBOutlet weak var image: UIImageView!
@IBOutlet weak var label: UILabel!
override init(frame: CGRect) {
super.init(frame: frame)
commonInit()
}
required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
commonInit()
}
func commonInit() {
let margin: CGFloat = -20
let backgroundView = UIView.init(frame: self.bounds)
backgroundView.backgroundColor = UIColor.eventTypeCellBackground()
self.backgroundView = backgroundView
let biggerBounds = CGRect(x: margin, y: margin, width: self.bounds.width-margin*2, height: self.bounds.height-margin*2)
let selectedBGView = UIView.init(frame: biggerBounds)
selectedBGView.backgroundColor = UIColor.eventTypeCellBackgroundHighlited()
self.selectedBackgroundView = selectedBGView
self.clipsToBounds = false
self.contentView.clipsToBounds = false
self.backgroundView?.clipsToBounds = false
self.selectedBackgroundView?.clipsToBounds = false
}
override func layoutSubviews() {
super.layoutSubviews()
if !oneTimeSetup {
label.textColor = UIColor.eventTypeLabelColor()
oneTimeSetup = true
}
}
}