๐ผ๏ธPoint
SwiftUI โฉ Drawing โฉ Shape โฉ Helper Shapes โฉ

โฌ๏ธ ้่ฆ๏ผ Frame
import SwiftUI
/// draw a relative point in a rect.
/// ```
/// Point(A) // A: UnitPoint
/// Point(A, .black, size: 20, label: "A")
/// ```
struct Point: View {
let point: UnitPoint
var color: Color = .pink
var size : CGFloat = 24
var label: String = ""
var body: some View {
GeometryReader { geo in
Circle()
// point color
.fill(color)
// point label
.overlay(Text(label).font(.caption).bold())
// point size
.frame(width: size, height: size)
// โญ๏ธ absolute position
// โญ๏ธ frame changed! ("push-out" view)
.position(geo.size[point]) // ๐
ฟ๏ธ Rectangular
}
}
}
// convenience init
extension Point {
init(
_ point: UnitPoint,
_ color: Color = .pink,
size : CGFloat = 24,
label : String = ""
) {
self.init(point: point, color: color, size: size, label: label)
}
}
Last updated
Was this helpful?