【发布时间】:2018-08-16 15:45:20
【问题描述】:
我正在尝试将阴影应用到 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 属性:
我什至已经从 Sketch 中导出了阴影颜色:
cellShadow = UIColor(hue: 0.643, saturation: 0.061, brightness: 0.906, alpha: 0.5)//Alpha 0.5
这是 iPhone 上的输出:
这是 Sketch 中的设计:
为什么 iPhone 上的阴影会消失,为什么颜色会有点不同(我正在使用颜色选择器查看是否匹配但不匹配)?我做错了什么,谁能告诉我?
【问题讨论】:
-
@Dule 不,我的影子在底部被切掉了。