简体   繁体   中英

How to add wave border to uiview?

I'm trying to add a bottom border like below programmatically. I believe I would need to use Beizer path, but not sure how should I go about the path points? Result image

private func setupBorder() {
    let shapeLayer = CAShapeLayer()
    let path = UIBezierPath(rect: frame)

    shapeLayer.path = path.cgPath
    layer.insertSublayer(shapeLayer, at: 0)
}

This way you can add wavy border:

func addDownwardCurve(to path: UIBezierPath?, to point: CGPoint, withAmplitude amplitude: CGFloat) {
let mid = (point.x + (path?.currentPoint.x ?? 0.0)) / 2
path?.addQuadCurve(to: point, controlPoint: CGPoint(x: mid, y: point.y + amplitude))
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM