Добавить внутреннюю тень в круг (UIBezierPath) - PullRequest
0 голосов
/ 18 апреля 2019

Я попытался добавить внутреннюю тень к кругу, нарисованному с помощью UIBezierPath.Однако код, кажется, не работает (он работает для UIView).Нужно добавить тень только к верхней части круга (дуга).

func drawCircleWithShadow() {
    //Draw Circle
    let path = UIBezierPath(arcCenter: CGPoint(x: 100, y: 400), radius: 150, startAngle: 0, endAngle: 6.2831853072, clockwise: true)
    let shapeLayer = CAShapeLayer()
    shapeLayer.path = path.cgPath
    let lightRedColor = UIColor(red: 255.0/255.0, green: 87.0/255.0, blue: 51.0/255.0, alpha: 1)
    shapeLayer.strokeColor = lightRedColor.cgColor
    shapeLayer.fillColor = UIColor.white.cgColor
    shapeLayer.lineWidth = 2.0
    shapeLayer.position = CGPoint(x: 100, y: 100)
    self.view.layer.addSublayer(shapeLayer)

    let innerShadow = CALayer()
    innerShadow.frame = shapeLayer.frame

    //Draw Shadow Arc
    let shadowPath = UIBezierPath(arcCenter: CGPoint(x: 100, y: 400), radius: 150, startAngle: 3.1415926536, endAngle: 4.7123889804, clockwise: true)
    let cutout = shadowPath.reversing()
    shadowPath.append(cutout)
    innerShadow.shadowPath = shadowPath.cgPath
    innerShadow.masksToBounds = true
    innerShadow.shadowColor = UIColor.black.cgColor
    innerShadow.shadowOffset = CGSize(width: 0, height: 3)
    innerShadow.shadowOpacity = 0.15
    innerShadow.shadowRadius = 3
    shapeLayer.addSublayer(innerShadow)
}
...