【发布时间】:2020-10-09 09:13:59
【问题描述】:
我需要为视图添加阴影,形状为梯形。
这是我的代码,但它不起作用。
[![enter image description here][1]][1]let trapezoidPath = UIBezierPath()
trapezoidPath.move(to: CGPoint(x: 0, y: 0))
trapezoidPath.addLine(to: CGPoint(x: Constants.padding, y: bounds.maxY - 10))
trapezoidPath.addLine(to: CGPoint(x: titleLabel.bounds.width + Constants.padding, y: bounds.maxY - 10))
trapezoidPath.addLine(to: CGPoint(x: titleLabel.bounds.width + 2 * Constants.padding, y: 0))
let trapezoidLayer = CAShapeLayer()
trapezoidLayer.path = trapezoidPath.cgPath
whiteView.layer.shadowPath = UIBezierPath(roundedRect: trapezoidPath.bounds, cornerRadius: whiteView.layer.cornerRadius).cgPath
whiteView.layer.shadowRadius = 15
whiteView.layer.shadowOffset = .zero
whiteView.layer.shadowOpacity = 0.4
whiteView.layer.masksToBounds = false
whiteView.layer.shadowColor = UIColor.red.cgColor
whiteView.layer.mask = trapezoidLayer
【问题讨论】:
标签: swift uibezierpath cashapelayer