0
我正在嘗試將角半徑添加到BottmLeft和bottomRight角,並且還爲其添加陰影。但由於某些原因,如果我添加角落半徑,陰影消失。這是什麼原因?設置角落半徑時未應用陰影
這是我做的:
我有擴展:
extension UIView {
func roundCorners(_ corners: UIRectCorner, radius: CGFloat) {
self.layoutIfNeeded()
let path = UIBezierPath(roundedRect: self.bounds, byRoundingCorners: corners, cornerRadii: CGSize(width: radius, height: radius))
let mask = CAShapeLayer()
mask.path = path.cgPath
self.layer.mask = mask
}
}
應用的角落:
myView.roundCorners([.bottomLeft, .bottomRight], radius: 35
)
添加陰影延伸:
func addShadow(offset: CGSize, color: UIColor, radius: CGFloat, opacity: Float) {
let layer = self.layer
layer.masksToBounds = false
layer.shadowOffset = offset
layer.shadowColor = color.cgColor
layer.shadowRadius = radius
layer.shadowOpacity = opacity
layer.shadowPath = UIBezierPath.init(roundedRect: layer.bounds, cornerRadius: layer.cornerRadius).cgPath
let backgroundCGColor = self.backgroundColor?.cgColor
self.backgroundColor = nil
layer.backgroundColor = backgroundCGColor
}
並添加陰影:
myView.addShadow(offset: CGSize.init(width: 0.0, height: 10.0) , color: UIColor.blue, radius: 35.0, opacity: 1.0)
爲什麼添加圓角後陰影消失?
嘗試添加self.clipsToBounds = false – ignotusverum