0

I have created a view that is curved from bottom. I have to drop a shadow below the curved path.

func addBottomRoundedEdge(desiredCurve: CGFloat?) {
    let offset: CGFloat = self.frame.width / desiredCurve!
    let bounds: CGRect = self.bounds
    let rectBounds: CGRect = CGRect(x: bounds.origin.x, y: bounds.origin.y, width: bounds.size.width, height: bounds.size.height / 2)
    let rectPath: UIBezierPath = UIBezierPath(rect: rectBounds)
    let ovalBounds: CGRect = CGRect(x: bounds.origin.x - offset / 2, y: bounds.origin.y, width: bounds.size.width + offset, height: bounds.size.height)
    let ovalPath: UIBezierPath = UIBezierPath(ovalIn: ovalBounds)
    rectPath.append(ovalPath)

    let maskLayer: CAShapeLayer = CAShapeLayer()
    maskLayer.frame = bounds
    maskLayer.path = rectPath.cgPath
    self.layer.mask = maskLayer
}
tomerpacific
  • 4,704
  • 13
  • 34
  • 52
IOS Lerner
  • 11
  • 3

0 Answers0