Group Group Group Group Group Group Group Group Group

Draw Path in SwiftUI framework

Hello Bill,

After I read chapter 13: Drawing & Custom Graphics in yours, I try to complete some sharp with swiftUI but I do not know how to use “public mutating func addArc(tangent1End p1: CGPoint, tangent2End p2: CGPoint, radius: CGFloat, transform: CGAffineTransform = .identity)” this function.
Would u please show me some demo to let me know how to use it?

In most cases, you’ll probably want to use the addArc(center:radius:startAngle:endAngle:clockwise:) instead. It’s a bit more intuitive unless your use case needs the parameters in the other method.

The one you’ve asked about wants two points and will create a tangent line from the current point on the path to each point. The resulting arc will then be drawn such that those tangent lines only touch the arc at a single point each and the arc will stop and end at those points.

You’d call it something like: path.addArc(tangent1End: .init(x: 150, y: 150), tangent2End: .init(x: 150, y: 50), radius: 50)

It’s useful in some cases, but the other method is much easier to work with to get a specific shape into the path.