๐ฆPath
Last updated
Was this helpful?
Last updated
Was this helpful?
What's the difference between Shape and Pathโ
Path ๆฏไธๅ struct๏ผไธป่ฆๆฏ็จ็ตๅฐๅบงๆจ (absolute coordinates) ไพ็ซ่ทฏๅพใ
Shape ๆฏไธๅ protocol๏ผ้คไบๅฏไปฅ็จ็ตๅฐๅบงๆจ็ซ่ทฏๅพๅค๏ผๅฟ ่ฆๅฏฆ็พ็ .path(in: rect) ๆนๆณไนๆไพไบไธๅ CGRect ๅๆธ๏ผ่ฎๆๅๅฏไปฅๆ นๆ container ็็ธๅฐไฝ็ฝฎไพ็ซ่ทฏๅพใ ๐ Paul
โฌ๏ธ ้่ฆ๏ผ shape.outlined(), Frame
/// a custom shape
struct BlobShape: Shape {
func path(in rect: CGRect) -> Path {
Path { path in
// `CGRect` conforms to `Rectangular` protocol,
// which has `rect[x,y]` subscript method.
path.move(to: rect[0.5, 0])
path.addCurve(to: rect[1.0, 0.5], control1: rect[1.0, 0.0], control2: rect[1.0, 0.0])
path.addCurve(to: rect[0.5, 1.0], control1: rect[0.5, 0.5], control2: rect[1.0, 1.0])
path.addCurve(to: rect[0.0, 0.5], control1: rect[0.0, 1.0], control2: rect[0.5, 0.5])
path.addCurve(to: rect[0.5, 0.0], control1: rect[0.0, 0.0], control2: rect[0.0, 0.0])
path.closeSubpath()
}
}
}
/// a view containing a custom shape
struct BlobView: View {
var body: some View {
BlobShape()
.outlined( // ๐Shape+ext
fill: .linearGradient(
colors : [.yellow, .green, .blue],
startPoint: .topLeading,
endPoint : .bottomTrailing
),
strokeStyle: .init(lineWidth: 10)
)
.frame(width: 300, height: 300)
}
}
SwiftUI โฉ Path
objc.io โฉ SwiftUI Path Builder โฉ SwiftUI Path Builder: Detecting Taps โญ๏ธ
conforms to Shape.
Path+: helper extension for .dimension().
Paint Code (app)
SwiftUI โฉ Path โฉ .forEach(_:) - ๆญคๆนๆณๅฐๅบๆไฝไฝ็จโ