vBg.extCorner(corners: UIRectCorner(rawValue: UIRectCorner.bottomLeft.rawValue | UIRectCorner.bottomRight.rawValue), radii: kRadii)
//
// MARK: - 处理圆角
//
extension UIView {
/// 部分圆角
///
/// - Parameters:
/// - corners: 需要实现为圆角的角,可传入多个
/// - radii: 圆角半径
func extCorner(corners: UIRectCorner, radii: CGFloat) {
let maskPath = UIBezierPath(roundedRect: self.bounds, byRoundingCorners: corners, cornerRadii: CGSize(width: radii, height: radii))
let maskLayer = CAShapeLayer()
maskLayer.frame = self.bounds
maskLayer.path = maskPath.cgPath
layer.mask = maskLayer
// self.layer.masksToBounds = true
}
//
// MARK: - 圆角阴影
//
func extShadowColor(_ color: UIColor, radius: CGFloat) {
//视图没有加上阴影,子视图加上了阴影。后来发现是因为如果不给视图添加背景颜色,
//阴影就会显示到子视图上,为视图添加背景颜色后,问题解决。
layer.shadowColor = color.cgColor
layer.shadowOffset = CGSize(width: 0, height: 0)
layer.shadowOpacity = 0.7//阴影透明度
layer.shadowRadius = 2//阴影半径
layer.cornerRadius = radius
//路径阴影
let path = UIBezierPath(roundedRect: bounds, byRoundingCorners: .allCorners, cornerRadii: CGSize(width: radius, height: radius))
//设置阴影路径
layer.shadowPath = path.cgPath
}
}
网友评论