I am trying to create a drop shadow for my UITableViewCell
's but the CALayer
doesn't work like it suppose.
- Once it's only on the top of the cell.
- Once it's only on the bottom of the cell.
- Once it's on the bottom and top of the cell.
My custom cell have :
Global variable:
var l = CALayer()
Next as a cell is going to be reused I have to remove the layer from the super layer.
override func prepareForReuse() {
super.prepareForReuse()
l.removeFromSuperlayer()
}
I am setting a bounds and inserting the layer inside :
override func layoutSubviews() {
super.layoutSubviews()
l.frame = self.bounds
layer.insertSublayer(l, at: 0)
}
At the end layer
configurations are inside willDisplay cell:
l.backgroundColor = UIColor.rgbColor(red: 221, green: 221, blue: 221, alpha: 1.0).cgColor
l.position = CGPoint(x: bounds.width / 2, y: -bounds.height / 2 + 0.5)
l.bounds = CGRect(x: 0, y: 0, width: bounds.width, height: bounds.height)
l.shadowColor = UIColor.darkGray.cgColor
l.shadowOffset = CGSize(width: 0, height: 1)
l.shadowOpacity = 0.8
l.shadowRadius = 5.0
l.zPosition = -1
l
does not have cell. before becouse it is all going inside Custom cell methods.
Any ideas what am I missing ? Thanks!