I have a custom Shape in SwiftUI that is a series of CGPoints that form different lines.
I want to be able to draw a border around each individual path and right now the only thing I can think of is creating another Shape that takes the original CGPoints and adds x,y padding to each point but I wanted to see if there was another way that perhaps is built-in that I couldn't find.
For example, my shape is
-----
|
|
and I want to add a border Shape so I can detect when someone is in a bound where the # represents a new possible Shape around the original paths.
########
#----- #
######
#|#
#|#
#
Is there a way to implement this that is built in?
edit: code I'm currently thinking about to draw the border, very early but gives a gist of what I'm thinking
struct DrawShapeBorder: Shape {
var points: [CGPoint]
func path(in rect: CGRect) -> Path {
var path: Path = Path()
guard let startingPoint = points.first else {
return path
}
// go up
let upStartingPoint = CGPoint(x: startingPoint.x, y: startingPoint.y + 5)
path.move(to: upStartingPoint)
for pointLocation in points {
path.addLine(to: pointLocation)
}
return path
}
}