Iam trying to apply shadow to tableView
cell
, which is rounded.
So the cell view's hierarchy is:
-TableView
-Cell //height 85
-ContentView //height 85
-View //height 85
-RoundedView //height 65
And this is how I am applying the shadow:
extension UIView{
func dropShadow(x: CGFloat, y: CGFloat, cornerRadius: CGFloat, shadowRadius: CGFloat, color: CGColor, opacity: Float) {
self.layer.cornerRadius = cornerRadius //Give the view corner radius
self.layer.shadowColor = color //Shadow color
self.layer.shadowOffset = CGSize(width: x, height: y)//Offset like in Sketch X and Y
self.layer.shadowRadius = shadowRadius //It should be the blur in Sketch
self.layer.shadowOpacity = 1.0
self.layer.shadowPath = UIBezierPath(roundedRect: self.bounds, byRoundingCorners: .allCorners, cornerRadii: CGSize(width: cornerRadius, height: cornerRadius)).cgPath
self.layer.shouldRasterize = true
self.layer.rasterizationScale = UIScreen.main.scale
}
}
These are the Sketch properties:
I have even exported the shadow color from Sketch:
cellShadow = UIColor(hue: 0.643, saturation: 0.061, brightness: 0.906, alpha: 0.5)//Alpha 0.5
And this is the output on iPhone:
And this is the design in Sketch:
Why the shadow cuts on iPhone and why the color is different a little(I am using color picker to see if it matches but it is not matching)? What I am doing wrong, can anybody tell me?