5

Everything is in the Title.

I have a UITableView with cells. The cells has a Shadow (self.layer.shadow...).

The problem is that the shadow of one cell is Overlapping the cell above. How can I prevent this behavior ?

enter image description here

And here is the code in my cell :

    self.layer.shadowColor = UIColor.gray.cgColor
    self.layer.shadowOffset = .zero
    self.layer.shadowOpacity = 0.15
    self.layer.shadowRadius = 10
    self.layer.cornerRadius = 8
    backgroundColor = .white
Alexis Darnat
  • 581
  • 6
  • 13

1 Answers1

1

Use this code for adding shadow :-

self.layer.masksToBounds = false
self.layer.shadowOffset = CGSize(width: -1, height: 1)
self.layer.shadowOpacity = 0.2
self.layer.cornerRadius = 8
Aditya Srivastava
  • 2,630
  • 2
  • 13
  • 23
  • Still the same ! I tried to isolate the content in the contentView, and the shadow directly on the root layer with the offset, but nothing – Alexis Darnat Apr 29 '18 at 06:47
  • @AlexisDarnat It seems like you have not given the spacing between `TableView Cells` and that's why these shows overlapping. So you can do one thing, - Take a `UIView` in Tableview cell and put it's constraint trailing,leading,top,bottom as 8 points and then apply my above code on this `UIView` outlet rather than on `content view` of `Tableviewcell` – Aditya Srivastava Apr 29 '18 at 06:56