我正在尝试将阴影应用于tableView
cell
四舍五入的 。
所以单元格视图的层次结构是:
-TableView
-Cell //height 85
-ContentView //height 85
-View //height 85
-RoundedView //height 65
这就是我应用阴影的方式:
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
}
}
这些是草图属性:
我什至从 Sketch 中导出了阴影颜色:
cellShadow = UIColor(hue: 0.643, saturation: 0.061, brightness: 0.906, alpha: 0.5)//Alpha 0.5
这是 iPhone 上的输出:
这是 Sketch 中的设计:
为什么 iPhone 上的阴影会消失,为什么颜色会有点不同(我正在使用颜色选择器来查看它是否匹配但不匹配)?我做错了什么,有人可以告诉我吗?