-1

I have a cell with a translucent fill. Since the fill is translucent, I can see the shadow behind the fill. How can I hide the shadow under the cell's fill?

self.layer.cornerRadius = 6
self.layer.masksToBounds = false
self.layer.shadowOpacity = 0.8
self.layer.shadowColor = UIColor.black.withAlphaComponent(0.6).cgColor  
self.layer.shadowRadius = 2
self.layer.shadowOffset = CGSize(width: 5, height: 5)  

This is what I have:
ScreenShot
Desired result with transparent View:
ScreenShot2

Sergey Hleb
  • 152
  • 1
  • 16

2 Answers2

0

As per my Understanding you need this kind of View:

You can try this:

    let viewShadow = UIView(frame: CGRect(x: 0, y: 0, width: 200, height: 200))
    viewShadow.center = self.view.center
    viewShadow.layer.cornerRadius = 10.0
    viewShadow.layer.borderColor = UIColor.black.cgColor
    viewShadow.layer.borderWidth = 0.5
    viewShadow.backgroundColor = UIColor.white.withAlphaComponent(0.4)
    viewShadow.layer.shadowColor = UIColor.lightGray.cgColor
    viewShadow.layer.shadowOpacity = 1
    viewShadow.layer.shadowOffset = CGSize(width: 20.0, height:  20.0)
    viewShadow.layer.shadowRadius = 5
    self.view.addSubview(viewShadow)

Output

enter image description here

Hope this helps.

Abhirajsinh Thakore
  • 1,806
  • 2
  • 13
  • 23
-2

This might help. All we need to do is alter the shadow path.

    cell.layer.cornerRadius = 6
    cell.layer.masksToBounds = false
    cell.layer.shadowOpacity = 0.8
    cell.layer.shadowColor = UIColor.black.withAlphaComponent(0.6).cgColor
    cell.layer.shadowRadius = 2
    cell.layer.shadowOffset = CGSize(width: 5, height: 5)
    let rect = CGRect(x: cell.frame.origin.x, y: cell.frame.origin.y + cell.frame.size.height, width: cell.frame.size.width, height: 3)
    cell.layer.shadowPath = CGPath(roundedRect: rect, cornerWidth: 1, cornerHeight: 1, transform: nil)
Nischal
  • 9
  • 4